Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating to OmniAuth 1.0: undefined method `user_omniauth_authorize_path'

Trying to migrate my app from Rails 3.0 to 3.2, and as part of this I'm also updating Devise gem. Turned out that new Devise requires new OmniAuth gem. I have Facebook authorization configured with OmniAuth. After reading migration guide I've added also omniauth-facebook gem and configured it in devise.rb.

Now I'm getting this error:

ActionView::Template::Error (undefined method `user_omniauth_authorize_path' for #<#:0x00000003b01e88>)

I was using this path for the Facebook login button. What should I use now?

User model contains this (user.rb):

 # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable, :lockable and :timeoutable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable

Full server log:

Started GET "/" for 127.0.0.1 at 2012-02-22 10:39:27 +0200
Processing by PagesController#guardian as HTML
[paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Asset class
  Rendered pages/guardian.html.erb within layouts/application (955.6ms)
Completed 500 Internal Server Error in 1245ms

ActionView::Template::Error (undefined method `user_omniauth_authorize_path' for #<#<Class:0x00000003b213f0>:0x00000003b01e88>):
    30:     </p>
    31:             </td>
    32:             <td>
    33:             <%= link_to "Login with Facebook", user_omniauth_authorize_path(:facebook), :class => "login_with_facebook_button" %>
    34:             </td>
    35:         </tr>
    36:     </table>
      app/views/pages/guardian.html.erb:33:in `_app_views_pages_guardian_html_erb___1979224720320394612_27892940'

Update: Ok, I managed to get resolved this path issue. Now when clicking on Facebook login button, I'm getting this:

Started GET "/users/auth/facebook" for 127.0.0.1 at 2012-02-23 16:02:01 +0200

NoMethodError (undefined method `include?' for nil:NilClass):
  omniauth (1.0.2) lib/omniauth/strategy.rb:165:in `call!'
  omniauth (1.0.2) lib/omniauth/strategy.rb:148:in `call'
  warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
  warden (1.1.1) lib/warden/manager.rb:34:in `catch'
  warden (1.1.1) lib/warden/manager.rb:34:in `call'

This all is a bit confusing. The path problem resolved after I specified the :facebook params accodring to this tutorial: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview. Now I also noticed that I'm missing omniauth.rb from config/initializers folder, which is mentioned in the omniauth-facebook wiki. I've created omniauth.rb with the following content, but still getting the same problem:

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, ENV['APP_ID'], ENV['APP_SECRET']
  end
like image 666
Alexander Savin Avatar asked Feb 22 '12 09:02

Alexander Savin


2 Answers

I resolved this issue by running devise generators again. The two files that would need to be verified are: config/routes.rb and models/user.rb

In the routes.rb file, there will be a duplicate 'devise_for' right at the top and the user.rb will have default devise modules, so 'omniauthable' will need to be added here.

like image 118
Ashwin Avatar answered Nov 07 '22 01:11

Ashwin


Place devise :omniauthable on the user model.Currently my versions are devise 2.0.4, omniauth 1.1.0 & omniauth-facebook 1.2.0

like image 4
Thillai Narayanan Avatar answered Nov 07 '22 01:11

Thillai Narayanan