Rails 3 runner not detecting JSON gem?

I am trying to create a Ruby script to work with the Rails 3 environment .

However, whenever I run this rubyscript with a 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 can I do to fix this?

+3
source share
2 answers

I am not completely familiar with the internals of the Bundler, but it may be that it does not allow the requireuse of other gems other than in the Gemfile. Perhaps the addition gem 'json'will take care of this.

, ActiveSupport JSON, .

+2

require "json", . , ActiveSupport to_json .

0

Source: https://habr.com/ru/post/1787169/


All Articles