Best practices for static pages in rails app

rails-routing, ruby-on-rails

Solution

If the static pages list are not going to increase, then you can keep the list, but if you want a dynamic list like site/any_new_url , save the routes as

get 'site/:cms_page' => 'cms#show' # all requests matching site/any_page will go CmsController, show method

This will help reduce keep the routes from bloating, but the downside is you do not know what all routes are the valid ones. Your sample code can be

def show
  @page_data = Page.find_by_page(:params[:cms_page])
end

show.html.erb

<%= @page_data.html_safe %>

Problem

I am developing a app in ruby on rails for a local business. The pages are 'static', but changeable through a backend CMS I am building for them. Is there a best practice to creating a controller for static pages? Right now I have a sites controller with all static routes, like this. routes.rb ``` get "site/home" get "site/about_us" get "site/faq" get "site/discounts" get "site/services" get "site/contact_us" get "site/admin" get "site/posts" ``` or would I be better off creating member routes for the site controller like this without the crud, because a 'Site' will not need to have the CRUD. ``` resources :sites, :except => [:index, :new, :create, :update, :destroy] member do get :home get :about_us get :faq get :discounts get :services get :contact_us get :admin get :posts end ``` Or is there a best practice / better way? Any answers would be appreciated. Thanks

Original source