#config/routes.rb
resources :home, path: "", only: [] do
collection do
get :aboutus
get :contactus
end
end
Loop removed by @Sanket
This will create domain.com/aboutus
etc for all your pages
--
DRY
Although this is what you want, a much DRYer way to get it to work is to do the following:
#config/routes.rb
resources :home, path: "", only: :show #-> domain.com/:id
This means you can then use a gem such as friendly_id
to create a series of slugs for your pages, like this:
#app/models/page.rb
class Page < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: [:slugged, :finders]
#fields
id | slug | title | body | created_at | updated_at
end
#app/controllers/home_controller.rb
def show
@page = Page.find params[:id]
end
If you just want to render the pages without the model:
#app/controllers/home_controller.rb
def show
render "pages##{params[:id]}"
end
This will allow you to use the likes of domain.com/home/aboutus
in the most DRY way
--
Caveat
A big caveat to this is if you're going to be using app-wide slugs, you need to put them at the bottom of your routes.rb
file (so they will not interfere with other routes)