Search code examples
rubyjsonruby-on-rails-3rubygemsrunner

Rails 3 runner not detecting JSON gem?


I'm trying to create Ruby script to run with my Rails 3 environment.

However, whenever I run this rubyscript with Rails Runner, I get this error:

require 'rubygems'
require 'json'

@payload = {
"message" => "helloworld",
"station" => {"id"=>12345}
}.to_json

puts @payload

ERROR:

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require': no such file to load -- json (LoadError)
 from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
 from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `load_dependency'
 from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:554:in `new_constants_in'
 from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in `load_dependency'
 from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in `require'
 from createflags.rb:2
 from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/commands.rb:39:in `eval'
 from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/commands/runner.rb:47
 from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/commands.rb:39:in `require'
 from /usr/lib/ruby/gems/1.8/gems/railties-3.0.0.beta4/lib/rails/commands.rb:39
 from script/rails:6:in `require'
 from script/rails:6

Can someone please tell me what I can do to fix this?


Solution

  • I'm not totally familiar with the internals of Bundler, but it may be that it doesn't allow requireing other gems not in the Gemfile. Maybe adding gem 'json' would take care of this.

    Of course, ActiveSupport has its own JSON module, so there should be no need to pull in another gem.