Search code examples
ruby-on-railsruby-on-rails-pluginsruby-on-rails-3rack

Problem with require rack/openid in Rails 3 [native require work properly]


I install plugin open_id_authentication and have this error:

/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `require': no such file to load -- rack/openid (LoadError)

when I try to start rails server Actually, rack-openid installed in my system and i can load it from irb:

irb(main):001:0> require 'rack/openid'
=> true

I tried to add hack to Gemfile as I did with ruby-openid, but it did't help:

gem "ruby-openid", :require => "openid"
gem "rack-openid", :require => "rack/openid"

I also have tried

gem "ruby-openid", :require => "rack/openid"

but:

/usr/lib/ruby/gems/1.9.1/gems/bundler-0.9.7/lib/bundler/runtime.rb:38:in `require': no such file to load -- rack/openid (LoadError)

In rails 2.3.5 app there isn't this problem and I can't understand why it happens in Rails 3.


Solution

  • The problem is this code at the top of the plugin's init.rb

    if Rails.version < '3'
      config.gem 'rack-openid', :lib => 'rack/openid', :version => '>=0.2.1'
    end
    

    Bundler doesn't seem to pick up on the gem requirement so you are missing the rack-openid gem.

    The solution is to add the following to your Gemfile in place of ruby-openid. (rack-openid depends on ruby-openid but gems is aware of this and will install it as needed)

    gem 'rack-openid', '>=0.2.1', :require => 'rack/openid'
    

    Don't forget to run bundle install after updating your Gemfile.