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
2010-05-31 04:38:12
+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
2010-05-31 04:46:04
cool... thanks a lot
ashok
2010-06-01 06:30:19
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
2010-06-01 13:53:57