我在rails 4.2.7应用程序中使用带有omniauth-facebook gem的Devise。我目前收到以下错误The action 'facebook' could not be found for Devise::OmniauthCallbacksController
。我按照本指南https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview设置了应用程序。
我的文件如下所示,
的routes.rb
# easy routes for devise
devise_scope :user do
get 'login', to: "devise/sessions#new"
get 'signup', to: "devise/registrations#new"
# delete 'sign_out', to: 'devise/sessions#destroy', :as => :destroy_user_session
end
devise_for :users, :path => '', :path_names => {
:sign_in => 'login', :sign_out => 'logout',
:controllers => {
:omniauth_callbacks => "callbacks",
registrations: 'registrations'
}
}
devise.rb
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
callback_url: ENV['FB_CALLBACK'],
:scope => 'email',
:info_fields => 'email'
模型/ user.rb
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable,
:omniauth_providers => [:facebook]
callbacks_controller.rb
class CallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def failure
redirect_to root_path
end
end
当我尝试通过Facebook登录应用程序时发生错误。