Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

jRuby 1.7.11 - NameError: uninitialized constant Rails::Application::Railties #169

Closed
Allanon29 opened this Issue Mar 15, 2014 · 16 comments

Comments

Projects
None yet
3 participants

Hi Guys,

I get an error when I try to start Spree with rails s under jRuby 1.7.11 and Rails 4.0.3:
NameError: uninitialized constant Rails::Application::Railties

This doesn't occur in ruby 2.1.0
If I comment out the spree_auth_devise gem then rails s works, and spree starts.

Any idea why this happens?

Member

JDutil commented Mar 15, 2014

It would be related to this recent split of the frontend/backend, which uses Railties to determine whether you only need the frontend or backend or both here:
https://github.com/spree/spree_auth_devise/blob/master/lib/spree/auth/engine.rb#L52-L62

I don't know why this would work any differently in jruby than 2.1.0 though as it is a Rails thing. What does your Gemfile order look like? Or are you familiar with why Rails would behave differently on jruby because I'm not familiar with jruby I don't use it. It sounds like you just need to make sure Rails is initialized before Spree & This extension.

Hi jdutil,

Here is my gemfile:

source 'https://rubygems.org'

gem 'rails', '4.0.3'

platform :jruby do 
    gem 'activerecord-jdbcsqlite3-adapter'
end

platform :ruby do
    gem 'sqlite3'
end

gem 'sass-rails', '~> 4.0.0'

gem 'uglifier', '>= 1.3.0'

gem 'coffee-rails', '~> 4.0.0'

gem 'therubyrhino'

gem 'jquery-rails'

gem 'turbolinks'

gem 'jbuilder', '~> 1.2'

group :doc do
  gem 'sdoc', require: false
end

gem 'puma'

gem 'spree', :git => 'https://github.com/spree/spree.git', :branch => '2-2-stable'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => '2-2-stable'
gem 'spree_auth_devise', :git => 'https://github.com/spree/spree_auth_devise.git', :branch => '2-2-stable'

To my knowledge Rails should not behave any different on jRuby, except of course it uses a different db adapter.
There is another problem though which might effect this, and it is connected to the spree install generator, which I've already mentioned here: spree/spree#4275

I posted this issue on the jRuby mailing list also, so I hope someone will answer.

Member

JDutil commented Mar 16, 2014

Well the problem appears to be the same for both issues. Your rails app is not being initialized before spree is trying to run. Since Spree depends on Rails you will have to ensure Rails is being initialized, but I'm not sure what that entails for you. I suspect it's a difference in how jruby requires/initializes things, but I really don't know as I'm unfamiliar with it. Are you ensuring that your running your commands with bundle exec as that may resolve the problem for you if not.

Hi Jdutil,

Yes I tried to run the commands with bundle exec. In fact I tried it again now, by creating a new rails app under jRuby, then put spree 2-2-stable with spree_auth_devise into the Gemfile. Bundle runs successfully, but when I try to run bundle exec rails g spree:install (or without bundle exec) I get the previously mentioned error:
NameError: uninitialized constant Rails::Application::Railties
It won't even show the errors which I mentioned in spree/spree#4275

A bit more error reporting about the issue:

/Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:53:in `backend_available?': uninitialized constant Rails::Application::Railties (NameError)
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:64:in `Engine'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:6:in `Auth'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:5:in `Spree'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:4:in `(root)'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/devise.rb:1:in `(root)'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/devise.rb:20:in `(root)'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:1:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:1:in `(root)'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:2:in `each'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:2:in `(root)'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:1:in `each'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:1:in `(root)'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `require'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler.rb:131:in `tap'
    from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler.rb:131:in `require'
    from bin/rails:4:in `require'
    from bin/rails:4:in `(root)'
Member

JDutil commented Mar 19, 2014

It looks to me like bin/rails is requiring spree_auth_devise before rails, but it comes after rails in your Gemfile so I'm not sure why that would be. I wonder what would happen if you tried it with rails at the bottom of your gemfile.

Hi Jdutil,

I tried to put rails to the bottom of my gemfile, but still the same error occurs.
I've also tried to use spree master and spree_auth_devise master branches with rails 4.0.4. Same error. I tried to put rails 4.1 in my gemfile but spree doesn't support it yet.
I've also tried to turn invokedynamic on/off in jruby settings, but no effect.

Maybe one of these jRuby settings would help (I don't have a better guess right now):
https://github.com/jruby/jruby/wiki/ConfiguringJRuby

I posted an issue to the jRuby repo also:
jruby/jruby#1568

Member

JDutil commented Mar 20, 2014

Ok well as far as I'm aware it definitely needs to be first, but I'm surprised that to see that spree_auth_devise is in your stacktrace before spree itself or even rails itself... that should not be the case... I'm sorry I don't really have the time to investigate this myself, but the problem is very clear to me. Rails is simply not being loaded before Spree or even SpreeAuthDevise despite them being in your Gemfile in the proper order. I don't know how to fix this without learning the workings of your setup unfortunately so I hope your able to resolve this from your open issues on those projects. The errors you've provided here and on the Spree repo for the install generator are very clear that Rails is not loaded when they try to run... That obviously won't work since Spree depends upon Rails. Until your able to figure out why Rails is not being initialized before Spree I can't be of much help sorry.

Member

radar commented Mar 20, 2014

Maybe this is just not requiring the railties file correctly?

On Thu, Mar 20, 2014 at 4:09 AM, Allanon29 notifications@github.com
wrote:

A bit more error reporting about the issue:

/Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:53:in `backend_available?': uninitialized constant Rails::Application::Railties (NameError)
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:64:in `Engine'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:6:in `Auth'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:5:in `Spree'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/engine.rb:4:in `(root)'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/devise.rb:1:in `(root)'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/polyglot-0.3.4/lib/polyglot.rb:65:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree/auth/devise.rb:20:in `(root)'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:1:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:1:in `(root)'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:2:in `each'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/bundler/gems/spree_auth_devise-9d52fb1626e5/lib/spree_auth_devise.rb:2:in `(root)'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:1:in `each'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:1:in `(root)'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `require'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler.rb:131:in `tap'
  from /Users/Mate/.rbenv/versions/jruby-1.7.11/lib/ruby/gems/shared/gems/bundler-1.5.3/lib/bundler.rb:131:in `require'
  from bin/rails:4:in `require'
  from bin/rails:4:in `(root)'

Reply to this email directly or view it on GitHub:
#169 (comment)

Member

JDutil commented Mar 20, 2014

@radar I think this issue is bigger than that... If you look at the related spree/spree#4275 it appears the issue is also related to Rails in general just not being loaded properly before the generator.

Member

JDutil commented Mar 20, 2014

Also might as well mention it but here is a great fix: Why not just use MRI ruby 2.1.1? Do you REALLY need to use jruby? It's probably overkill causing you problems for no good reason to be honest...

Member

radar commented Mar 20, 2014

I am able to reproduce this on my machine. I am looking into it.

radar added a commit that referenced this issue Mar 20, 2014

Reference Rails::Engine::Railties within Engine
Referencing Rails::Application::Railties leads to an exception when running under JRuby

Fixes #169

@radar radar closed this in 6fdface Mar 20, 2014

Member

radar commented Mar 20, 2014

@Allanon29 I've fixed this up in the latest two commits to 2-2-stable and master. Can you please try running bundle update spree_auth_devise and let me know if that fixes it for you too?

@radar Thank You! Thank You!! Now it works.

@JDutil Thank You for Your help too. The reason why I use jRuby is because I want to use Torquebox for deployment (in fact the store I am building now is already deployed with Torquebox). You can read some performance benchmarks here (bit old but they used Spree for testing):
http://torquebox.org/news/2011/10/06/torquebox-2x-performance/
There is also a good presentation on slideshare here:
http://www.slideshare.net/lanceball/complex-made-simple-sleep-better-with-torquebox-12718812

The issue I mentioned here is still present though, but I can work around it:
spree/spree#4275

And most importantly I need 2 addresses to send "some" beer to! :)

Member

JDutil commented Mar 20, 2014

Nice thanks @radar still interested to see how spree/spree#4275 can be resolved.

Impressive benchmarks would like to see more up to date ones if you ever have some spare time to test out your deployment options.

@JDutil I am interested in that too. No answer yet from the jRuby guys. I will ask on the IRC channel too.

Sure. When I am ready with my current project I will do a benchmark on a VPS with TB, Puma, Passenger, Unicorn. All of them with NGINX. Will post it in the Google Group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment