문제

I'm using "therubyracer" in a model, and I'm requiring at the top of the model as so:

require 'v8'
class Thing
  def self.ctx; @@ctx ||= V8::Context.new; end;

  def self.eval(script); ctx.eval(script); end;
end

However, I intermittently get:

NameError - uninitialized constant Thing::V8: 
/app/thing.rb:3:in `ctx'

When testing requests through a local Padrino server, apparently after I modify code in Thing. This is corrected by restarting the padrino server. I'm assuming requiring v8 somewhere else would fix this problem, wheres the correct place?

도움이 되었습니까?

해결책

This looks like it might be caused by the Padrino reloader getting confused when it reloads your thing.rb file, causing Ruby to look for V8 in the Thing namespace.

Try explicitly specifying V8 is in the top level using the :: prefix:

def self.ctx; @@ctx ||= ::V8::Context.new; end;

다른 팁

You can put it wherever you want if you add it on the Gemfile. Did you added it?

Thanks!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top