Eric Conner Eric Conner - 9 months ago 23
Ruby Question

How do I get an installed ruby gem included in Rails?

I am attempting to get a gem I installed working in a Rails application. I can require the gem just fine in a Ruby program that I run from the command line using:

require 'nokogiri'

But when I attempt to do the same in one of my Rails controllers it errors saying "no such file to load -- nokogiri".

I tried using the full path to the lib/nokogiri.rb file, but that fails because it cannot find "nokogiri/native".

Answer Source

Better, place the following in your environment.rb file: do |config|
  config.gem :nokogiri

This will tell Rails that you depend on that particular gem. It also allows you to specify particular versions, and it will automatically keep all your gems synched, or unpack them into vendor/gems if you so wish.