0

I've gotten my application to work (i.e. sign_in and sign_up) with Authlogic and I'm now trying to add support for OAuth through the Authlogic_OAuth gem. I've gotten all of the basics set up (I think) and I've added a "Login with Twitter" button to my landing page. The problem is that when I click the button I get this error:

 uninitialized constant UserSession::OAuth

with the application trace:

app/models/user_session.rb:17:in `oauth_consumer'
app/controllers/user_sessions_controller.rb:23:in `create'

The function that is failing is in my user_session model:

# authlogic_oauth hacks                                                       
# Twitter example                                                             
def self.oauth_consumer
  OAuth::Consumer.new("TOKEN", "SECRET",
      { :site => "http://twitter.com",
        :authorize_url => "http://twitter.com/oauth/authenticate"})
end

I'm pretty new to rails and ruby so I don't quite understand where this namespace collision is coming from or how to solve it. Any help would be greatly appreciated.

spinlock
  • 3,737
  • 4
  • 35
  • 46

2 Answers2

2

OK, I figured it out. The problem is that OAuth::Consumer is not defined withing authlogic_oauth. It's actually defined in the oauth gem. so I updated my Gemfile to:

gem 'authlogic', '2.1.6'
# set up oauth capabilities. Note: :lib is replaced with :require in rails 3
gem 'authlogic-oauth', '1.0.8', :require => 'authlogic_oauth'
gem 'oauth', '0.4.4'

then run:

bundle install

and, don't forget to restart the rails server so that it reloads the gems from the Gemfile.

spinlock
  • 3,737
  • 4
  • 35
  • 46
1

Try to change OAuth to ::OAuth. The colons mean that you want to access OAuth from outside your class. It was searching from your class.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Guilherme Bernal
  • 8,183
  • 25
  • 43
  • 1
    That doesn't seem to be it. Adding that scope just results in the error changing to "uninitialized constant OAuth". Thanks for the comment though. – spinlock Mar 16 '11 at 23:58