Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails3 - oauth-plugin problem

I'm trying to use oauth-plugin on a Rails application I'm developing, but I keep running into problems.

To make sure I'm not making any mistake, I started an application from scratch (using Rails 3.0.3). Here are the steps I followed:

  1. Create da new rails application (rails.test)
  2. Edited its Gemfile to include:

    gem "oauth-plugin", ">=0.4.0.pre1"
    gem "oauth", "0.4.4"
    
  3. Generated oauth-consumer, by running script/rails g oauth_consumer

  4. Edited oauth_consumers.rb to include my keys for Google integration:

    :google=>{ 
      :key=>"anonymous", 
      :secret=>"anonymous",
      :scope=>"https://www.google.com/calendar/feeds/", 
      :options => {
        :site => "http://www.google.com", 
        :request_token_path => "/accounts/OAuthGetRequestToken", 
        :access_token_path => "/accounts/OAuthGetAccessToken", 
        :authorize_path=> "/accounts/OAuthAuthorizeToken"
      },
    }
    
  5. Edited routes.rb to add the route for oauth_consumer:

    resources :oauth_consumers
    
  6. Edited application_controller.rb to implement the logged_in? method as follows:

    def logged_in?
        true
    end
    
  7. Now when I access http://localhost:3000/oauth_consumers/google I get the following error:

    uninitialized constant GoogleToken
    

Does anyone know what causes this error and how can I fix it? GoogleToken is a class that should have been auto generated by oauth-plugin, so I can't tell why I'm getting this uninitialized constant error.

like image 363
pgb Avatar asked Feb 11 '26 19:02

pgb


1 Answers

The GoogleToken class doesn't get auto-generated unless you pass "google" to the generator like so:

script/rails g oauth_consumer google

or for rails 3:

rails g oauth_consumer google

Also check to ensure the relationship is set up in the user model like so:

has_one  :google, :class_name => "GoogleToken", :dependent => :destroy
like image 82
billiamram Avatar answered Feb 14 '26 10:02

billiamram