6

I couldn't get jruby to work with Rails 4 without a hack:

In railties/lib/rails/engine.rb, I had to initialize Railties with const_get, otherwise

def railties
  @railties ||= self.class.const_get(:Railties).new
  # @railties ||= self.class::Railties.new
 end

Otherwise I get this:

./bin/rake rake aborted! uninitialized constant Myapp::Application::Railties org/jruby/RubyModule.java:2677:in const_missing' /Volumes/Opt/rails/rails-edge/railties/lib/rails/engine.rb:469:inrailties' /Volumes/Opt/rails/rails-edge/railties/lib/rails/application.rb:241:in run_tasks_blocks' /Volumes/Opt/rails/rails-edge/railties/lib/rails/engine.rb:444:inload_tasks' org/jruby/RubyBasicObject.java:1659:in __send__' org/jruby/RubyKernel.java:2086:insend' /Volumes/Opt/rails/rails-edge/railties/lib/rails/railtie/configurable.rb:30:in method_missing' /Volumes/Opt/projects/myapp/Rakefile:6:in(root)' org/jruby/RubyKernel.java:1046:in `load'

Rails itself won't start up for the same reason. Is this the correct fix or did I mask some underlying problem?

4

2 回答 2

3

并没有真正解决问题,但我补充说

Rails::Engine.class_eval do
  def railties
    @railties ||= self.class.const_get(:Railties).new
  end
end

Bundler.requireinapplication.rb以避免更改原始文件。

于 2013-01-25T21:55:50.487 回答
0

这似乎已通过向 Rails master 提交(对引擎的小改动)得到修复:https ://github.com/rails/rails/commit/45aabe61520cbb4bd74f6de7dc1023d2ca071e40

我刚刚补充说:

gem 'rails', :git => 'git://github.com/rails/rails.git'  

要不就

gem 'rails', github: 'rails/rails'

到我的 Gemfile 来下载最新版本的 Rails,这样就成功了。能够删除亚历克斯(很好 - 谢谢!)的黑客攻击,一切正常。

于 2013-03-22T08:50:14.513 回答