Develop Omniauth undefined omniauth_authorize_path method

I noticed that when I logged in to Devise, I started getting these error messages.

I am using Devise 2.2.4 with Omniauth 1.1.4 and Omniauth-Facebook 1.4.1

Does anyone 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' 
+6
source share
6 answers

One possible error is that omniauth configuration is installed in the wrong place.

I ran into this error because I set facebook accounts in config/initializers/omniauth.rb as described in readmom.

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

+11
source

I started getting this error today (July 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 .

+8
source

Try

 user_omniauth_authorize_path(provider) 

I assume that you have a User class and in your routes file there is

 devise_for :users 
+2
source

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 allows you to use it for multiple providers, but assumes that you are using

 devise_for :users 

But even further you can also add

 resource_class.name.downcase 

to reach not only the 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 a user and provider, then it will create a path:

user_facebook_omniauth_authorize_path

if devise_for is the twitter admin and provider, then it will do the path:

admin_twitter_omniauth_authorize_path

0
source

Utility changed omniauth_authorize_path(<scope>, <provider>) url omniauth_authorize_path(<scope>, <provider>)

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

0
source

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

change

omniauth_authorize_path

to

user_omniauth_authorize_path(provider)

0
source

Source: https://habr.com/ru/post/954594/