Skip to content

Add pages to a Rails application, including controllers, views, routing, and tests.

License

Notifications You must be signed in to change notification settings

RailsApps/rails_apps_pages

Repository files navigation

RailsApps Page Gem RailsApps Pages Gem

Use this gem to add pages to a Rails application, including controllers, views, routing, and tests.

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 tool. Use Rails Composer to build any of the RailApps example applications for use as starter apps.

If you like the RailsApps Pages gem, you might be interested in the RailsLayout gem which generates Rails application layout files for various front-end frameworks such as Bootstrap and Foundation.

Join RailsApps

From the RailsApps Project

The RailsApps open source project offers starter applications and tutorials for Rails developers. Generate the applications with the Rails Composer tool.

All the code is explained in the Capstone Rails Tutorials. You can purchase the Capstone Rails Tutorials to support the project.

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

Use Bundler

Use Bundler to install the gems:

$ bundle install

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
  • plus tests (if RSpec is installed)

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.

Generate an “About” Page

To run the generator and create an “About” page:

$ rails generate pages:about

The generator will create:

  • app/views/pages/about.html.erb
  • plus tests (if RSpec is installed)

You’ll need to install the high_voltage gem for the “About” page. The high_voltage gem makes it easy to add pages with static content (text that doesn’t change), incorporating a site-wide application layout. The high_voltage gem provides the controller and routes needed to display any pages found in the app/views/pages/ folder.

Generate User Pages Requiring Authentication

If you have a User model and authentication with Devise or OmniAuth, you can add pages to display a list of users or each user’s profile, restricted to signed in users.

To run the generator and create pages to accompany a User model:

$ rails generate pages:users

The generator will create:

  • app/controllers/users_controller.rb
  • app/controllers/visitors_controller.rb
  • app/views/users/_user.html.erb
  • app/views/users/index.html.erb
  • app/views/users/show.html.erb
  • app/views/visitors/index.html.erb

It will also add routes to the config/routes.rb file.

Generate User Pages Requiring Authorization

If you have a User model, authentication with Devise, and authorization with Pundit, you can 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 with Pundit authorization:

$ rails generate pages:authorized

All files are identical to the rails generate pages:users generator, except:

  • app/views/users/_user.html.erb
  • app/controllers/users_controller.rb
  • app/policies/user_policy.rb
  • plus tests (if RSpec is installed)

Clean a Gemfile

Remove commented lines and multiple blank lines from a Gemfile:

$ rails generate clean:gemfile

Clean a Routes File

Remove commented lines and multiple blank lines from the file config/routes.rb:

$ rails generate clean:routes

Generate Analytics Files

Add a file containing JavaScript code to set up page-view tracking with Google Analytics:

$ rails generate analytics:google

Add a file containing JavaScript code to set up page-view tracking with Segment.io:

$ rails generate analytics:segmentio

Generate Bootstrap Page Layouts

See the Start Bootstrap site for a collection of Bootstrap themes and templates that you can generate with the rails_apps_pages gem.

Here are the Bootstrap page layouts you can generate:

 1)  None
 2)  1 Col Portfolio
 3)  2 Col Portfolio
 4)  3 Col Portfolio
 5)  4 Col Portfolio
 6)  Bare
 7)  Blog Home
 8)  Business Casual
 9)  Business Frontpage
10)  Clean Blog
11)  Full Width Pics
12)  Heroic Features
13)  Landing Page
14)  Modern Business
15)  One Page Wonder
16)  Portfolio Item
17)  Round About
18)  Shop Homepage
19)  Shop Item
20)  Simple Sidebar
21)  Small Business
22)  Stylish Portfolio
23)  The Big Picture
24)  Thumbnail Gallery

To see the commands that generate the Bootstrap page layouts, run:

$ rails g

Issues

Any issues? Please create an issue on GitHub. Reporting issues (and patching!) helps everyone.

Credits

Daniel Kehoe maintains this gem as part of the RailsApps project.

Please see the CHANGELOG for a list of contributors.

Is the gem useful to you? Follow the project on Twitter: @rails_apps. I’d love to know you were helped out by the gem.

MIT License

MIT License

Copyright © 2014 Daniel Kehoe

Useful Links

Getting Started Articles Tutorials
Ruby on Rails Analytics for Rails Rails Bootstrap
What is Ruby on Rails? Heroku and Rails Rails Foundation
Learn Ruby on Rails JavaScript and Rails RSpec Tutorial
Rails Tutorial Rails Environment Variables Rails Devise Tutorial
Ruby on Rails Tutorial for Beginners Git and GitHub with Rails Devise RSpec
Install Ruby on Rails Send Email with Rails Devise Bootstrap
Install Ruby on Rails – Mac OS X Haml and Rails Rails Membership Site with Stripe
Install Ruby on Rails – Ubuntu Rails Application Layout Rails Subscription Site with Recurly
Ruby on Rails – Nitrous.io HTML5 Boilerplate for Rails Startup Prelaunch Signup Application
Update Rails Example Gemfiles for Rails
Rails Composer Rails Application Templates
Rails Examples Rails Product Planning
Rails Starter Apps Rails Project Management

About

Add pages to a Rails application, including controllers, views, routing, and tests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published