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?
depends on the url structure, if you want the paths to come off of / (e.g. /about_us), then:
This should go at the very end of your routes file, Throw your .html.erb files into app/views/static and you are done.
e.g: throwing in
about_us.html.erb
, will give you a page at /about_us.The item that you have in your question is great for a catch all route where you can analyze the array given to you at
params[:path]
. A bit more information on that at http://railscasts.com/episodes/46-catch-all-routeRendering an action doesn't make sense. You'll want to render a template (or a file) with a layout.
You could serve a variety of different templates from a single action with page caching.
Lastly, we'll need to define a route.
Try accessing these static pages. If the path doesn't include a valid template, we'll render the 404 file and return a 404 status.
http://localhost:3000/static/static1
http://localhost:3000/static/static3
http://localhost:3000/static/static2
If you take a look in app/public you'll notice a static/ directory with static1.html, static2.html and static3.html. After accessing the page for the first time, any subsequent requests will be entirely static thanks to page caching.