h1. !http://railsapps.github.io/images/rails-36x36.jpg(RailsApps Page Gem)! RailsApps Pages Gem Use this gem to add pages to a Rails application, including controllers, views, and routing. RailsApps Pages is a utility gem to use during development. You can remove it after generating the pages you need. It was originally written for use by the "Rails Composer":http://railsapps.github.io/rails-composer/ tool. Use Rails Composer to build any of the "RailApps example applications":http://railsapps.github.io/ for use as starter apps. If you like the RailsApps Pages gem, you might be interested in the "RailsLayout gem":https://github.com/RailsApps/rails_layout which generates Rails application layout files for various front-end frameworks such as Bootstrap and Foundation. h4. !http://railsapps.github.io/images/join/join-railsapps.png(Join RailsApps)!:http://railsapps.github.io/ h4. Support the RailsApps Project If the RailsApps Pages gem is useful to you, please accept our invitation to "join the RailsApps project":http://railsapps.github.io/. The RailsApps project provides example applications, tutorials, and starter tools, including the RailsApps Pages gem. h2. Install the Gem Add the gem to your Rails application Gemfile:
group :development do
  gem 'rails_apps_pages'
end
You don't need the RailsApps Pages gem deployed to production, so put it in the @development@ group. If you want to use a newer unreleased version from GitHub:
group :development do
  gem 'rails_apps_pages', github: 'RailsApps/rails_apps_pages'
end
h4. Use Bundler Use Bundler to install the gems:
$ bundle install
h2. Generate a Home Page To run the generator and create a home page:
$ rails generate pages:home
The generator will create: * app/views/visitors/index.html.erb * app/controllers/visitors_controller.rb It will add a route to the *config/routes.rb* file:
root :to => "visitors#index"
Why a "Visitors" controller? Why not a "Home" controller or "Welcome" controller? Those names are acceptable. But the home page often implements a user story for a persona named "visitor," so a "Visitors" controller is appropriate. h2. Generate User Pages Requiring Authentication If you have a User model and authentication with Devise, you might want to add pages to display a list of users or each user's profile, restricted to logged in users. To run the generator and create pages to accompany a User model:
$ rails generate pages:users
The generator will create: * app/views/visitors/index.html.erb * app/controllers/visitors_controller.rb * app/views/users/_user.html.erb * app/views/users/index.html.erb * app/views/users/show.html.erb * app/controllers/users_controller.rb It will add routes to the *config/routes.rb* file:
resources :users
root :to => "visitors#index"
h2. Generate User Pages Requiring Authorization If you have a User model, authentication with Devise, and authorization with Pundit, you might want to add pages to display a list of users, restricted to an administrator. Each user can see his or her own profile if logged in. To run the generator and create pages to accompany a User model:
$ rails generate pages:authorized
The generator will create: * app/views/visitors/index.html.erb * app/controllers/visitors_controller.rb * app/views/users/_user.html.erb * app/views/users/index.html.erb * app/views/users/show.html.erb * app/controllers/users_controller.rb It will add routes to the *config/routes.rb* file:
resources :users
root :to => "visitors#index"
All files are identical to the @rails generate pages:users@ generator, except: * app/views/users/_user.html.erb * app/controllers/users_controller.rb h2. Clean a Gemfile Remove commented lines and multiple blank lines from a Gemfile:
$ rails generate clean:gemfile
h2. Clean a Routes File Remove commented lines and multiple blank lines from the file *config/routes.rb*:
$ rails generate clean:routes
h2. Issues Any issues? Please create an "issue":http://github.com/RailsApps/rails_apps_pages/issues on GitHub. Reporting issues (and patching!) helps everyone. h2. Credits Daniel Kehoe maintains this gem as part of the "RailsApps project":http://railsapps.github.io/. Please see the "CHANGELOG":https://github.com/RailsApps/rails_apps_pages/blob/master/CHANGELOG.textile for a list of contributors. Is the gem useful to you? Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps. I'd love to know you were helped out by the gem. h2. MIT License "MIT License":http://www.opensource.org/licenses/mit-license Copyright © 2014 Daniel Kehoe