views:

35

answers:

2

What is the difference between having require 'gem_name' in a controller and config.gem "gem_name" in environments.rb? I'm new to RoR, and am looking through an app and can't work out the difference. Thanks for reading.

+1  A: 

"environments.rb" is a file that contains various configuration setting for your application, e.g. which gem the application needs to run correctly (mainly for portability). They have to be specified using config.gem "gem_name". This post about Gem Dependencies could help you.

With require "gem_name" you can explictly import a gem into your code in order to be able to use it´s classes.

auralbee
A: 

config.gem in your environment.rb is needed to set up the correct rails environment. For example if you download a ruby app from github you can run rake gems:install from the application directory and all the correct versions of the required gems will be installed.

require in a controller is like import in vb.net and allows the classes in that gem to be used in your controller.

Damian