Rails Brochure: Static Pages Gem

29 Jan 2011

I just extracted a pattern I have been repeating in all of my recent rails applications. The gem is called Rails Brochure and it's a Rails engine for brochure pages. Similar to High Voltage but with named routes.

Brochure pages are the semi-static pages like "home", "about us", "FAQ", "pricing", "contact us", etc.

Once installed all you need to do is create template files in your app/views/home folder and it adds named routes to those views.

For Example

file path                          accessible at     named route
views/home/about.html.erb          /about            about_url
views/home/faq.html.haml           /faq              faq_url
views/home/about/company.html.erb  /about/company    about_company_url

Most of the designers I have worked with really appreciate the power and convenience this provides. They are used to creating HTML or PHP files and having the URLs just work. This lets them do this with .erb files. No futzing with routes, controllers etc.

On an unrelated note I've been building a lot of sinatra apps lately. To get the functionality of the rails-brochure gem in sinatra all you need is:

# put this at the bottom of your app to make it lowest-priority catch-all route
get '/*' do
  erb params["splat"].to_s.to_sym
end