Ryan Bates给出了很棒的截屏视频http://railscasts.com/episodes/360-facebook-authentication如何使用"omniauth-facebook“gem。但也有一些问题:
#application_controller.rb
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user它将@current_user设置得太晚,以至于无法为控制器中的操作设计身份验证保护:
before_filter :authenticate_user!, :except => [:index, :show]所以它重定向到登录页面,即使是@current_user在视图中也是可用的…
也许有人知道如何修复它?
另外,我看到了一些重定向处理器的技巧,但我认为应该有更好的决定…
发布于 2013-06-05 23:05:52
我已经找到了使用标准设计方法登录的简单方法。基于本教程,只需在sessions_controller中设置代码:
#sessions_controller.rb
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["omniauth.auth"])
sign_in user
redirect_to root_url
end
end您可以从应用程序控制器中将其删除:
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_userhttps://stackoverflow.com/questions/16941850
复制相似问题