Premium Content - Free Preview
One of the major benefits of Rails is the large ecosystem that has developed around it, particularly the amount of open source code available for free. A huge amount of open-source Ruby projects are published on Github, where people can browse the source code, report issues, or contribute to the actual code.
When you find Ruby code that you want to use, you could theoretically download it and figure out how to include it in your project. However, no one likes manually installing, configuring and updating code or software, so Ruby developers instead distribute their code in easy-to-install packages called Gems. Gems are similar to browser extensions that are easily installed and updated.
Most Ruby Gems are published on RubyGems.org and downloaded from there. To browse gems by category and popularity, see ruby-toolbox.com. Once you've found the gem you want, it's time to add it to your application! In Rails, you specify what gems your application uses in the gemfile. This file is located in the root folder of your app, so go ahead and open it up. The gemfile primarily contains gems from the default Rails gemfile, along with a few additions for this tutorials.
source 'https://rubygems.org' #source where gems are installed from # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 4.2.1' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # ... # (more general gems...) # ... # These gems are only for your development and test environments: group :development, :test do # Use sqlite3 as the database for Active Record. Heroku does not allow this in production. gem 'sqlite3' # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', '~> 1.3.6' # Stop tests at first failure gem 'minitest-fail-fast', '~> 0.0.1' # Adjusts test output gem 'learneroo-gem' end # These gems are only for your production environment group :production do # These two gems are required for Heroku: gem 'pg' gem 'rails_12factor' end
Your Rails app runs in different environments, i.e.
development when your developing it and in
production for the live site for actual visitors. Most gems are installed for all environments, but you can also specify that certain gems should only be installed for a specific environment. In the above gemfile, two gems are installed just for
production, since they're required by Heroku.
End of Free Content Preview. Please Sign in or Sign up to buy premium content.