Looking at different options:
One is to just put the static pages in the public/ folder, but I do want the header from layout/application to be consistent.
I tried this, but I got an error:
# in routes.rb:
map.connect '*path', :controller => 'content', :action => 'show'
# in content_controller.rb:
def show
render :action => params[:path].join('/')
end
All I want is an easy way to put together things like my faq, contact, tos, privacy, and other non-application type pages somewhere easy by just creating an .rhtml. who has done this?
Lindsaar solution is one of the best I ever seen. He build a caching static pages that expired when git revision changed.
Create a PagesController for your static pages (e.g contact) and insert
in config/routes.rb insert
which will display the content from views/pages/contact_page.html.erb
I used the idea of a generalized controller from the answers given, but I wanted to catch 404s, so I put an action in it to handle either case:
and then at the very bottom in my routing:
It serves the view from
app/views/static
of the same name as the path, and if there isn't such a view, it servesapp/views/static/not_found.html.erb
. One could also replacerender :not_found
withredirect_to root_path
or anything else one wanted to have happen.thoughtbot has a plugin called high_voltage for displaying static content: https://github.com/thoughtbot/high_voltage
For Rails5 and Rails4 you can do the following:
Put the line below at the end of your routes.rb
Then requests to root/welcome, will render the /app/views/static/welcome.html.erb.
Don't forget to create a 'static' controller, even though you don't have to put anything in there.
For Rails3 you have to use 'match' instead of 'get'
Considering if u have 1 Home Controller with couple method like show, aboutus, privacy :
And map the show method to your root, and map the other to some named routes like
And with view for each
All using the same layout at app/views/layout/application.html.erb