views:

136

answers:

4

I tried adding a few gems to my Rails app using the config.gem instruction in environment.rb so that when the app gets deployed on a new system, the missing gems issue can be taken care of with rake gems:install

After adding the list of required gems that my app depends on, my app failed to start. If I remove the list of required gems from the environment.rb file the app starts fine.

The comment in environment.rb says

# You have to specify the :lib option for libraries, where the Gem name (sqlite3-ruby) differs from the file itself (sqlite3)

I am pretty much certain that I am missing the :lib option for one of the gems, how does one find if the gem is a library and the library name for it?

+4  A: 

It's not that there are "library gems" and "non-library gems". It's rather that Rails automatically requires all gems that are loaded by config.gem. The way that Rails knows what to require is what you specify with :lib. If you don't specify anything, it tries to require the name of the gem.

For example:

config.gem 'simple-navigation'

will require the 'simple-navigation' gem, which does not work. You have to instead specify:

config.gem 'simple-navigation', :lib => 'simple_navigation'

Look at the instructions for the gems you require and see if their directions ask you to require something different. (If one of them contains a hyphen, for example, it's probably going to be an underscore in the resulting :lib reference.)

John Feminella
@John, Thank you. "Look at the instructions for the gems you require and see if their directions ask you to require something different." - How and where do I find those instructions?
Anand
Each gem should have a README file or something to this effect which outlines how it's intended to be used. (Sometimes they require more specific configuration than just being included; this is where you find that information.)
John Feminella
+1  A: 

My tried and true method of finding the correct library (if not included in the readme, which I've found to often been the case) is to run

gem spec

and then looking through the file list, especially in the lib/ directory. Usually the one with the name closest to the gem itself is the one I'm looking for. Obviously this is not %100 reliable, but its worked for me alright.

For example gem spec ruby-plsql gives

--- !ruby/object:Gem::Specification 
name: ruby-plsql

....    

extra_rdoc_files: 
- History.txt
- License.txt
- README.txt
files: 
- History.txt
- License.txt
- README.txt
- lib/oradate_patch.rb
- lib/plsql/connection.rb
- lib/plsql/jdbc_connection.rb
- lib/plsql/oci_connection.rb
- lib/plsql/package.rb
- lib/plsql/procedure.rb
- lib/plsql/schema.rb
- lib/ruby_plsql.rb
- lib/ruby_plsql/version.rb
- spec/plsql/package_spec.rb
- spec/plsql/procedure_spec.rb
- spec/plsql/schema_spec.rb
- spec/spec.opts
- spec/spec_helper.rb
has_rdoc: true
homepage: http://ruby-plsql.rubyforge.org
licenses: []

....

rubyforge_project: ruby-plsql
rubygems_version: 1.3.4
signing_key: 
specification_version: 2
summary: ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures.
test_files: []

And I see

lib/ruby_plsql.rb

and since the gem is named ruby-plsql, I'm gonna take a guess that it might be the main lib file. You can also check the .gemspec file to see what it is building to.

Lukas
+1  A: 

gem which require is helpful

rogerdpack
+1  A: 

Actually, 'gem contents ' will list the files inside the gem, which will give you the clue.

odigity