Myapp::Application::Railties constant missing with Rails 4 beta and Jruby jruby-1.7.2
Asked Answered
M

2

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?

Milli answered 25/1, 2013 at 18:9 Comment(3)
I'm also seeing this in jruby 1.7.3Vidrine
I have jruby 1.7.4.dev installed and same thing - Rails won't start NameError: uninitialized constant MyAppName::Application::RailtiesCochrane
solved (see answer below)Cochrane
S
3

Doesn't really solve the problem but I added

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

under Bundler.require in application.rb to avoid having to change the original files.

Shortcut answered 25/1, 2013 at 21:55 Comment(0)
C
0

This appears to have been fixed with this commit to Rails master (small change to engine): https://github.com/rails/rails/commit/45aabe61520cbb4bd74f6de7dc1023d2ca071e40

I just added:

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

or just

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

to my Gemfile to pull down the latest version of Rails, and that did the trick. Was able to delete Alex's (nice - thankyou!) hack and it all works as it should.

Cochrane answered 22/3, 2013 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.