Skip to content

junfengy/rails-bootstrap

 
 

Repository files navigation

Rails Bootstrap Rails and Bootstrap

Deploy to Heroku Hack RailsApps on Nitrous.IO

Rails 4.1 example application that integrates Rails and Bootstrap 3.2.

Bootstrap (formerly Twitter Bootstrap) provides CSS stylesheets and JavaScript code for the visual design of websites. Bootstrap is a framework for client-side (browser-based or “front end”) development, much like Ruby on Rails is a framework for server-side development.

Use this example application as a starter app for your own web applications.

You can build this application in only a few minutes using the Rails Composer tool.

Resources for Rails and Bootstrap

The RailsApps project provides both a book and Quickstart Guide to help you get up to speed with Bootstrap and Rails. Please join the RailsApps project to get both the book and the Quickstart Guide. Subscriptions provide financial support for the RailsApps project.

Rails Bootstrap

If you are new to Rails, start with Learn Ruby on Rails, the best Rails book for beginners.

Follow on Twitter Follow on Twitter

Follow the project on Twitter: @rails_apps. Please tweet some praise if you like what you’ve found.

What Is Implemented — and What Is Not

The example application can be used as the basis for any website. It shows the simplest approach to implementing a website, using practices recommended by experienced Rails developers. With knowledge of Rails, the website can be adapted and customized to your needs. Features include:

  • Home page
  • “About” page
  • Navigation bar

Additional Pages

The application uses the high_voltage gem for the “About” page. Additional pages can easily be added. The high_voltage gem makes it easy to add pages with static content (text that doesn’t change) incorporating elements of a site-wide application layout such as header, navigation links, and footer.

For example, using the high_voltage gem, you could add pages for:

  • FAQ
  • News
  • Legal disclaimers

Database

The application does not require a database. No pages are generated using information from a database and no user-submitted data is saved to a database. However, the sqlite3 gem is included in the Gemfile so Rails ActiveRecord can be used to add database functionality to the web application.

Tutorial Application

Additional features implemented in the tutorial include:

  • Image carousel
  • Survey form
  • Google spreadsheet datastore
  • Modal window

These features demonstrate how Bootstrap can be used with Rails but are not needed in a starter application.

SimpleForm

Developers often use the SimpleForm gem with Rails. SimpleForm version SimpleForm 3.1.0.rc1 (and newer) integrates with Bootstrap 3.2.

Similar Examples and Tutorials

This is one in a series of Rails example apps and tutorials from the RailsApps Project. See a list of additional Rails examples, tutorials, and starter apps. Related example applications may be useful:

Accounts You Will Need

We provide instructions to deploy the tutorial application to Heroku which provides Rails application hosting. It costs nothing to set up a Heroku account and deploy as many applications as you want. To deploy an app to Heroku, you must have a Heroku account. Visit Heroku to set up an account.

Dependencies

Before generating your application, you will need:

  • The Ruby language – version 2.1
  • The Rails gem – version 4.1

See the article Installing Rails for instructions about setting up Rails and your development environment.

Getting the Application

Local

You have several options for getting the code on your own machine. You can fork, clone, or generate.

Fork

If you’d like to add features (or bug fixes) to improve the example application, you can fork the GitHub repo and make pull requests. Your code contributions are welcome!

Clone

If you want to copy and customize the app with changes that are only useful for your own project, you can clone the GitHub repo. You’ll need to search-and-replace the project name throughout the application. You probably should generate the app instead (see below). To clone:

$ git clone git://github.com/RailsApps/rails-bootstrap.git

You’ll need git on your machine. See Rails and Git.

Generate

If you want to use the project as a starter application, use the Rails Composer tool to generate a new version of the example app. You’ll be able to give it your own project name when you generate the app. Generating the application gives you additional options.

To build the example application, Rails 4.1 must be installed in your development environment. Run the command:

$ rails new rails-bootstrap -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

The $ character indicates a shell prompt; don’t include it when you run the command.

This creates a new Rails app named rails-bootstrap on your computer. You can use a different name if you wish.

You’ll see a prompt:

question  Build a starter application?
      1)  Build a RailsApps example application
      2)  Contributed applications
      3)  Custom application

Enter “1” to select Build a RailsApps example application. You’ll see a prompt:

question  Starter apps for Rails 4.1. More to come.
      1)  learn-rails
      2)  rails-bootstrap
      3)  rails-foundation
      4)  rails-omniauth
      5)  rails-devise
      6)  rails-devise-pundit

Choose rails-bootstrap. The Rails Composer tool may give you other options (other applications may have been added since these notes were written).

The application generator template will ask you for additional preferences:

 question  Web server for development?
       1)  WEBrick (default)
       2)  Thin
       3)  Unicorn
       4)  Puma
       5)  Phusion Passenger (Apache/Nginx)
       6)  Phusion Passenger (Standalone)
 question  Web server for production?
       1)  Same as development
       2)  Thin
       3)  Unicorn
       4)  Puma
       5)  Phusion Passenger (Apache/Nginx)
       6)  Phusion Passenger (Standalone)
 question  Template engine?
       1)  ERB
       2)  Haml
       3)  Slim
 question  Test framework?
       1)  None
       2)  RSpec with Capybara
   extras  Set a robots.txt file to ban spiders? (y/n)
   extras  Create a GitHub repository? (y/n)
   extras  Use or create a project-specific rvm gemset? (y/n)

Web Servers

We recommend Thin in development for speed and less noise in the log files.

If you plan to deploy to Heroku, select Thin as your production webserver. Unicorn is recommended by Heroku but configuration is more complex.

Template Engine

The example application uses the default “ERB” Rails template engine. Optionally, you can use another template engine, such as Haml or Slim. See instructions for Haml and Rails.

Testing

If you are a beginner, select “None.”

Other Choices

Set a robots.txt file to ban spiders if you want to keep your new site out of Google search results.

If you choose to create a GitHub repository, the generator will prompt you for a GitHub username and password.

It is a good idea to use RVM, the Ruby Version Manager, and create a project-specific rvm gemset (not available on Windows). See Installing Rails.

Troubleshooting

If you get an error “OpenSSL certificate verify failed” or “Gem::RemoteFetcher::FetchError: SSL_connect” see the article OpenSSL errors and Rails.

Cloud

Click the button below to install the app on Nitrous.io, a hosted development environment. Nitrous.io is free for small projects. See Ruby on Rails with Nitrous.io for more information.

Hack RailsApps on Nitrous.IO

Edit the README

If you’re storing the app in a GitHub repository, please edit the README files to add a description of the app and your contact info. If you don’t change the README, people will think I am the author of your version of the application.

Getting Started

See the article Installing Rails to make sure your development environment is prepared properly.

Use RVM

I recommend using rvm, the Ruby Version Manager, to create a project-specific gemset for the application. If you generate the application with the Rails Composer tool, you can create a project-specific gemset.

Gems

Here are the gems used by the application:

These gems make development easier:

Install the Required Gems

If you used the Rails Composer tool to generate the example app, the application template script has already run the bundle install command.

If not, you should run the bundle install command to install the required gems on your computer:

$ bundle install

You can check which gems are installed on your computer with:

$ gem list

Keep in mind that you have installed these gems locally. When you deploy the app to another server, the same gems (and versions) must be available.

Configuration File

To consolidate configuration settings in a single location, store credentials in the config/secrets.yml file. To keep your credentials private, use Unix environment variables to set your credentials. See the article Rails Environment Variables for more information.

This is the default config/secrets.yml file:

development:
  secret_key_base: (not shown)

The example application does not require any configuration settings. The file config/secrets.yml is provided in case you need to customize the application with features that require configuration settings.

If you don’t want to use Unix environment variables, you can set each value directly in the config/secrets.yml file. The file must be in your git repository when you deploy to Heroku. However, you shouldn’t save the file to a public GitHub repository where other people can see your credentials.

Change your Application’s Secret Token

If you’ve used the Rails Composer tool to generate the application, the application’s secret token will be unique, just as with any Rails application generated with the rails new command.

However, if you’ve cloned the application directly from GitHub, it is crucial that you change the application’s secret token before deploying your application in production mode. Otherwise, people could change their session information, and potentially access your site without permission. Your secret token should be at least 30 characters long and completely random.

Get a unique secret token:

rake secret

Edit the config/secrets.yml file to change the secret token.

Test the App

You can check that your application runs properly by entering the command:

$ rails server

To see your application in action, open a browser window and navigate to http://localhost:3000/.

You should see a home page with a placeholder headline.

You should be able to click the navigation link for “About” and see a placeholder page.

Stop the server with Control-C. If you test the app by starting the web server and then leave the server running while you install new gems, you’ll have to restart the server to see any changes. The same is true for changes to configuration files in the config folder. This can be confusing to new Rails developers because you can change files in the app folders without restarting the server. Stop the server each time after testing and you will avoid this issue.

Deploy to Heroku

Heroku provides low cost, easily configured Rails application hosting.

One Click Deployment

For one-click deployment, click the button to deploy to Heroku:

Deploy to Heroku

From the Command Line

Alternatively, you can deploy from the command line.

You’ll need to precompile assets before you commit to git and push to Heroku:

$ RAILS_ENV=production rake assets:precompile
$ git add -A
$ git commit -m "assets compiled for Heroku"
$ git push origin master

If you’ve set configuration values in the config/secrets.yml file, you’ll need to set them as Heroku environment variables. You can set Heroku environment variables directly with heroku config:add. For example:

$ heroku config:add GMAIL_USERNAME='[email protected]' GMAIL_PASSWORD='secret'

Complete Heroku deployment with:

$ git push heroku master

See the Tutorial for Rails on Heroku for details.

Troubleshooting

Problems? Check the issues.

Documentation

The Tutorial provides additional documentation.

Issues

Please create a GitHub issue if you identify any problems or have suggestions for improvements.

Where to Get Help

Your best source for help with problems is Stack Overflow. Your issue may have been encountered and addressed by others.

You can also try Rails Hotline, a free telephone hotline for Rails help staffed by volunteers.

Contributing

If you make improvements to this application, please share with others.

Send the author a message, create an issue, or fork the project and submit a pull request.

If you add functionality to this application, create an alternative implementation, or build an application that is similar, please contact me and I’ll add a note to the README so that others can find your work.

Credits

Daniel Kehoe implemented the application and wrote the tutorial.

Is the app useful to you? Follow the project on Twitter: @rails_apps
and tweet some praise. I’d love to know you were helped out by what I’ve put together.

MIT License

MIT License

Copyright ©2013-14 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

githalytics.com alpha

About

Rails 4.1 starter app with the Bootstrap front-end framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 92.0%
  • CSS 5.5%
  • JavaScript 2.5%