This is an extremely simple rails 3.2+ engine that lets you create static pages just by adding templates to your views directory.
Add this line to your Gemfile, and run bundle install:
gem 'static_pages', :git => 'https://github.com/tortus/static_pages.git'
Add this line to the bottom of config/routes.rb (or elsewhere if you know what you're doing):
mount StaticPages::Engine, :at => '/'
Change '/' to whatever path you would prefer pages to be accessible at.
- Create a template in app/views/static_pages/pages/, for example: app/views/static_pages/pages/test.html.erb
- Visit /test in your browser
If you create index.html, it will be used as your site's home page if you have no other "root" specified.
Use the static_pages.page_path helper:
static_pages.page_path("page_template_name_here")
The engine uses the following routes:
match ':page(.:format)' => 'pages#show', :as => :page, :via => :get
root :to => 'pages#index'
The controller functionality boils down to the following, after security checks:
def show
render params[:page]
end
If the template isn't found, the ActionView::TemplateNotFound exception is caught and re-thrown as ActionController::RoutingError.
The pages controller ensures that params[:page] is a string, and that it only contains alpha-numeric characters before calling render. If the page does not meet these criteria, an ActionController::RoutingException is raised.
Currently the pages controller only responds to the HTML format.