Reputation: 49
How to resolve a NameError for Omniauth paths in Rails view? I'm currently implementing Omniauth authentication in my Rails application. In my view file, I have the following code:
<div class="social_login">
<div class="">
<%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path, type: "button", class: "social_box fb" %>
<%= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path, type: "button", class: "social_box google" %>
</div>
</div>
routes.rb:
devise_for(:user, {
class_name: 'Spree::User',
singular: :spree_user,
controllers: {
sessions: 'user_sessions',
registrations: 'user_registrations',
passwords: 'user_passwords',
confirmations: 'user_confirmations',
omniauth_callbacks: 'users/omniauth_callbacks'
},
omniauth_controller.rb:
class OmniauthController < ApplicationController
def facebook
@user = Spree::User.create_from_provider_data(request.env['omniauth.auth'])
if @user.persisted?
sign_in_and_redirect @user
else
flash[:error] = 'There was a problem signing you in through Facebook. Please register or try signing in later.'
redirect_to new_spree_user_registration_url
end
end
def google_oauth2
@user = Spree::User.create_from_provider_data(request.env['omniauth.auth'])
if @user.persisted?
sign_in_and_redirect @user
else
flash[:error] = 'There was a problem signing you in through Google. Please register or try signing in later.'
redirect_to new_spree_user_registration_url
end
end
def failure
flash[:error] = 'There was an error signing you in. Please try again.'
redirect_to root_path
end
end
Could someone please guide me on how to correctly reference the Omniauth paths in the view? What should the correct paths be, and how can I ensure they are properly defined?
Any help or insights would be greatly appreciated!
Upvotes: 0
Views: 46