Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>During your development in Rails, there will be times where you will want to provide some functionality which is required by you, but either you don't know how to do or you don't want to implement it on your own since a lot of work has been put into its development by talented developers.</p> <p>These developments which you might need (user authentication, message system, asset handlers, geolocation, pagination system, linking to exterior services such as Amazon AWS, and last but not least Rails itself) are called Ruby Gems. These are ruby software packages, not necessarily relating to Rails, but since Rails is based on Ruby, 98% of the gems can be made availble to your Rails webapp code.</p> <p>Lots of gems can be found in <a href="http://github.com">github</a>, but its funner to search for gems via <a href="http://rubygems.org/">ruby-gems</a> or <a href="https://www.ruby-toolbox.com/">ruby-toolbox</a> </p> <p>Your <code>gemfile</code> is a list of all gems that you want to include in the project. It is used with <a href="http://gembundler.com/">bundler</a> (also a gem) to install, update, remove and otherwise manage your used gems.</p> <p>The <code>gemfile</code> has another purpose - you can group gems in <code>:development</code>, <code>:test</code>, <code>:assets</code>, <code>:production</code>, etc groups and Rails will know when to include the gems. For example:</p> <pre><code>group :development, :test do gem "rspec-rails" gem "factory_girl_rails" gem "guard-rspec" end </code></pre> <p>Note that on Rails 4, the <code>assets</code> group has been deprecated </p> <p>These gems belong to development environment and the test environment since they are for testing the application. You don't need them available in the production environment (you could, but that will bloat the memory unnecessarily).</p> <p>So - To use the <code>gemfile</code>, simply write the gem you wish to install such as</p> <pre><code>gem 'devise' </code></pre> <p>make sure to install <code>bundler</code> beforehand (in your console/cmd/ssh) with </p> <pre><code>$ gem install bundler </code></pre> <p>and then write in the console</p> <pre><code>bundle install </code></pre> <p>you will notice another gemfile appears! <code>Gemfile.lock</code> This file, as you will see if you open it with a text reader, lists all your gems with their version and their dependencies. This will come useful when you need to know which versions of the gems you installed.</p> <p>For more reading on the <code>Gemfile</code> - <a href="http://gembundler.com/gemfile.html">read on the bundler page</a></p> <p>for information regarding picking a gem you could start with <a href="http://www.railstutors.com/blog/how-to-pick-the-right-ruby-gem">this</a></p> <p>Good luck and have fun!</p> <hr> <p><strong>Ok, so whats this Gemfile.lock that got created?</strong></p> <p>Gemfile.lock, as the name suggests is a locking on all the versions of all the gems that got installed. So if Gemfile is what required to be installed, the lock file is what got installed and what version are actually required to get the app up and running.</p> <p>If you don't have the gems in that specific version (as specified in Gemfile.lock) rails will complain and you will have to either install the missing gems (via <code>bundle install</code>) or fix any conflicts manually (I believe bundler will give you some clues on that)</p> <p><strong>Some things to know about <code>Gemfile.lock</code></strong></p> <ul> <li>if you accidently delete it, it will get regenerated when you run <code>bundle install</code>. If you accidently delete <code>Gemfile</code>, you are out of luck.. You should use git :)</li> <li>Heroku doesn't care about Gemfile.lock since it will reinstall all gems. So for Heroku, you <em>must</em> set the gem version you want, or Heroku will always install the latest version of gem, which may cause issues</li> <li>Keep the Gemfile.lock in your project so you will always know what version of gems make your app work properly.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload