简体   繁体   中英

Combining pengwynn linkedin gem with devise/omniauth?

I'm trying to follow this link for help integrating the linkedin gem with an omniauthable devise Rails platform.

http://renderedtext.com/blog/2011/08/17/how-to-use-linkedin-gem-with-omniauth/

Two quick questions!

  1. Where would the bottom "class LinkedinFactory" file be located within the app, and what would it be called? I don't see a directory/filename in the link above.

  2. My application currently fails when I try to log in through linkedin saying:

    NoMethodError in OmniauthCallbacksController#linkedin

    undefined method `create_linkedin_connection' for nil:NilClass

Where and how would I define the "create_linkedin_connection" method? It is called in line 3 of the omniauth_callbacks.rb controller:

def linkedin
    omniauth_hash = env["omniauth.auth"]
    current_user.create_linkedin_connection(
      :token  => omniauth_hash["extra"]["access_token"].token,
      :secret => omniauth_hash["extra"]["access_token"].secret,
      :uid    => omniauth_hash["uid"]
    )
    redirect_to root_path, :notice => "You've successfully connected your LinkedIn account."
  end

Thank you!

1) A user defined class should usually get put in your lib directory

2) You are calling the "create_linkedin_connection" method on current_user, in which case that method needs to be in the Users controller. Once that has been changed then you need to make sure to specify the route in your routes.rb file. The route should be defined as so

match '/auth/callback', to: 'users#create_linkedin_connection'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM