设计:从控制器登录 [英] Devise : Sign in from a controller
本文介绍了设计:从控制器登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要登录fron non-devise控制器。我找到了此链接devise wiki,但我得到错误:
错误的参数数量(2为0)
我在链接中确实很喜欢。什么地方出了错?感谢
我的代码:
sign_in(:site, find(params [si]))
解决方案
sign_in(:user,User.find(params [:id])
如果你在看到current_user设置之后执行binding.pry。
由于某种原因,执行重定向之后会使current_user为零。 p>
这就是为什么我在会话中设置一些东西,然后重定向,然后检查会话id是否设置,然后使用它来执行上面的代码:
session [:new_user_id] = params [:id]
I need to sign in fron non-devise controller. I found this link from devise wiki, but I get error :
wrong number of arguments (2 for 0)
I did exactly like in the link. What went wrong? Thanks
My code :
sign_in(:site, Site.find(params["si"]))
解决方案
sign_in(:user, User.find(params[:id])
If you do a binding.pry after you'll see that current_user is set.
For some reason, doing a redirect after this will make current_user nil.
That's why I set something in the session like this and then redirect, and then check if that session id is set and then use it to do the above code:
session[:new_user_id] = params[:id]
这篇关于设计:从控制器登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文