16

I've noticed that when logging to Devise I have started to receive these error message.

I'm using Devise 2.2.4 with Omniauth 1.1.4 and Omniauth-Facebook 1.4.1

Does anybody know what is the cause of this error?

  ActionView::Template::Error (undefined method `omniauth_authorize_path' for #<#<Class:0xb85e534>:0xb904e5c>):
21: <%- if devise_mapping.omniauthable? %>
22:   <%- resource_class.omniauth_providers.each do |provider| %>
23:     <% logger.info "hey #{provider} , dolphin and #{resource_name}" %>
24:     <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
25:   <% end -%>
26: <% end -%>

  app/views/devise/shared/_links.erb:24:in `block in _app_views_devise_shared__links_erb___1039642231_94147460'
  app/views/devise/shared/_links.erb:22:in `each'
  app/views/devise/shared/_links.erb:22:in `_app_views_devise_shared__links_erb___1039642231_94147460'
  app/views/devise/sessions/new.html.erb:17:in `_app_views_devise_sessions_new_html_erb__883448937_92868060'
Ashitaka
  • 19,028
  • 6
  • 54
  • 69
kambi
  • 3,291
  • 10
  • 37
  • 58

7 Answers7

21

One possible mistake is that omniauth configuration is set at the wrong place.

I encountered this error because I set my facebook accounts in config/initializers/omniauth.rb, as instructed by the omniauth readme.

However we need to set it through devise, i.e. config/initializers/devise.rb at the omniauth section.

lulalala
  • 17,572
  • 15
  • 110
  • 169
11

I started getting this error today (Jul 27, 2016) when I upgraded to Ruby 2.3.1 and Rails 4.2.7. The solution that worked for me was to change all instances of user_omniauth_authorize_path(:twitter) to user_twitter_omniauth_authorize_path.

Justin Schier
  • 524
  • 5
  • 14
6

Try

user_omniauth_authorize_path(provider)

I'm assuming you have a User class and in your routes file you have

devise_for :users
Ashitaka
  • 19,028
  • 6
  • 54
  • 69
3

Do it like that

<%- if devise_mapping.omniauthable? %>
  <%- resource_class.omniauth_providers.each do |provider| %>
    <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", public_send("user_#{provider.to_s}_omniauth_authorize_path") %><br />
  <% end -%>
<% end -%>

This makes it usable for multiple providers but it assumes you are using

devise_for :users

But going even further you could also add

resource_class.name.downcase

to cover not only user

<%- if devise_mapping.omniauthable? %>
  <%- resource_class.omniauth_providers.each do |provider| %>
     <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", public_send("#{resource_class.name.downcase}_#{provider.to_s}_omniauth_authorize_path") %><br />
  <% end -%>
<% end -%>

If devise_for is users and provider is facebook, then it will make path:

user_facebook_omniauth_authorize_path

if devise_for is admins and provider twitter, then it will make path:

admin_twitter_omniauth_authorize_path

Riiwo
  • 1,839
  • 3
  • 15
  • 18
2

Devise changed the url helper to be omniauth_authorize_path(<scope>, <provider>)

See here: http://www.rubydoc.info/github/plataformatec/devise/Devise%2FOmniAuth%2FUrlHelpers%3Aomniauth_authorize_path

Aeramor
  • 330
  • 2
  • 10
2

If you initialize your devise providers in config/initializers/omniauth.rb You should include Devise::OmniAuth::UrlHelpers in your config/initializers/omniauth.rb or config/initializers/devise.rb

Yaroslav
  • 131
  • 1
  • 2
1

In your app/views/devise/shared/_links.erb :

change

omniauth_authorize_path

to

user_omniauth_authorize_path(provider)

Rupali
  • 311
  • 3
  • 5