Lau*_*ent 6 ruby-on-rails omniauth
我正在使用推特的宝石.在回调时,检查用户是否存在并创建他或将他发送回主页.
我可能做错了,但在我的回调代码中,request.env ['omniauth.origin']是零.
我的代码非常简单:
whatever.html.erb
<%= link_to image_tag("twitter-connect.png"), "/auth/twitter" %>
Run Code Online (Sandbox Code Playgroud)
的routes.rb
match "/auth/:provider/callback" => "sessions#create"
Run Code Online (Sandbox Code Playgroud)
sessions_controller.rb
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
if !user.email
redirect_to confirm_path, :notice => "Add your email!"
else
redirect_to request.env['omniauth.origin'] || root_url, :notice => "Signed in!"
end
end
Run Code Online (Sandbox Code Playgroud)
如果我在回调后立即提出request.env ['omniauth.origin'],我会得到一个nil对象.
谢谢你的帮助!