views:

45

answers:

2

I have installed gem successfully.But how can we use use in controller?

A: 

Add require 'gem' to top of controller or specific method.

Sample use of rubyzip gem for ex

def zip(data, filename)
   require 'zip/zip'
   require 'zip/zipfilesystem'
   zipfile = "/tmp/rubyzip-#{rand 32768}"
   Zip::ZipOutputStream::open(zipfile) do |io|
     io.put_next_entry(filename)
     io.write data
   end
   zippy = File.open(zipfile).read
   File.delete(zipfile)
   zippy
end
tstevens
+1  A: 

Look inside of config/environment.rb. Inside of the Rails::Initializer.run block you should see a commented-out note that describes using config.gem.

You want to add the gem that you need with that method, like this:

config.gem "foo"

There are other options that you might need, depending on what gem you are trying to use. Mention what it is, and I can be more specific.

Also be sure to read the docs for the gem method.

jdl
cool... thanks a lot
ashok
You're welcome. If it answered your question, please click the checkmark and the up-arrow. On this, and any other questions you ask on this site. It's the coin of the realm around here.
jdl