views:

213

answers:

2

I'm having trouble getting rubygems to work in my Rails app. Specifically, I'm trying to use the json gem, documented here: http://flori.github.com/json/ I can successfully use JSON.parse() in IRB and script/console but not in my rails app.

I know it's some combination of config.gem 'json' in environment.rb and other things, but can't find a good explanation anywhere.

Can someone give me a concise list of what is required to use this gem OR point me towards comprehensive documentation of using gems in Rails? thanks!

+1  A: 

config.gem is used for gem dependency in rails and it does nothing more than telling rails that a gem is needed, and helping the user install the appropriate gem, etc (more details here: http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies)

however by installing a gem, it should be able to be used by the rails app automatically, if not, probably you can add require "json" into environment.rb or in an .rb files in the initializers folder?

Hope it helps =)

Staelen
Thanks! Really appreciate the help.
Graham
A: 

I solved it. There's decent documentation here: http://apidock.com/rails/Rails/Configuration/gem

Once you have used config.gem in environment.rb, you should not need to 'require' it later.

My problem was that I had not stopped and restarted the server! It worked in script/console because everything was getting reloaded every time.

Graham