Simple dynamic yet static pages for a Rails app
In your Gemfile add the following:
gem 'pages'
Then you can either create a app/views/pages
directory
mkdir app/views/pages
Or run the generator
rails g pages:setup
Simply define new pages in your routes
Rails.application.routes.draw do
# Define a single page
page :about
# Define multiple pages
pages :contact, :team
end
This will expand to:
get '/about' => 'pages#about', :as => :about
Then just create a new view
touch app/views/pages/about.html.erb
And create whatever content you want!
If you'd like to modify the routes that Pages generates, you can alter the page parameter by passing an options hash containing a block. This is particularly useful for creating SEO-friendly routes:
page :press_kit, :transform => lambda { |page| page.dasherize }
would expand to:
get '/press-kit' => 'pages#press_kit', :as => :press_kit
You can easily namespace pages:
namespace :work do
pages :client_1, :client_2
end
This will create a Work::PagesController
dynamically if one does not
already exist. If you chose to create your own it should always inherit
from ::PagesController
. Your views should be put into
app/views/work/pages/
You can optionally override the path helpers by passing a hash to :as
pages '404', '500', as: { '404' => 'not_found', '500', => 'server_error' }
Your views will be app/views/pages/not_found.html
and
app/views/pages/server_error.html
and path helpers will be not_found_path
and server_error_path
but the urls will be /400
and /500
.
We are very thankful for the many contributors
This gem follows Semantic Versioning
Stable branches are created based upon each minor version. Please make pull requests to specific branches rather than master.
Please make sure you include tests!
Unles Rails drops support for Ruby 1.8.7 we will continue to use the hash-rocket syntax. Please respect this.
Don't use tabs to indent, two spaces are the standard.
DockYard, LLC © 2012