如何调用来自不同色器件另一个控制器设计色器件sign_in和SIGN_OUT方法呢? [英] How to call devise sign_in and sign_out methods of devise from another controller different from devise?

查看:160
本文介绍了如何调用来自不同色器件另一个控制器设计色器件sign_in和SIGN_OUT方法呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我on Rails的3.0.7应用Rub​​y和我与用户身份验证制定,但我有一个另外的注册登录方法,我让我的用户注册使用其的Facebook 帐户,然后我保存登录在我的用户表的同一个就是图谋使用登记和信息登录用户。

I have a Ruby on Rails 3.0.7 application and my user authentication with devisebut and I have an alternative sign up and sign in methods, I allow my users to sign up using their Facebook account then I save that login info in my users table the same one that devise uses to register and login users.

步骤


  1. ✔用户点击Facebook上的按钮。

  2. ✔我保存他的信息(名称,并从考拉提取电子邮件)我给用户一个通用密码。

  3. ☐登录用色器件该新用户。

  4. ✔重定向到我的主控制器。

  1. ✔ User click on the Facebook button.
  2. ✔ I save his info (name and email extracted from Koala) I give the user a generic password.
  3. ☐ Login this new user with devise.
  4. ✔ Redirect to my main controller.

我只是错过了第三步,因为我想用 CURRENT_USER 帮助和 user_signed_in?保持帮手了。

I'm just missing the 3rd step because I want to keep using the current_user helper and the user_signed_in? helper too.

所以,我怎么告诉制定本用户自动从我的其他控制器签?

So how do I tell devise to sign in this user automatically from my other controller?

我看到了类似的东西在这个问题上设计:有多个控制器处理而且记录我的用户,但使我的用户会话到一个空白页...

I saw something like that on this question Devise: Have multiple controllers handle user sessions and it logs my user in but leads me to an blank page...

推荐答案

设计提供一堆助手的,其中两个是这些:

Devise offers a bunch of helpers, two of which are these:

sign_in(resource_or_scope, *args)
sign_in_and_redirect(resource_or_scope, *args)

您可以从任何控制器使用这些。

You can use these from any controller.

修改

如果使用 sign_in 已经为你的作品,但留下一个空白页上的用户,请检查你的日志文件,看看是否有一个重定向回事,它重定向到。或者只是让重定向通过明确使用上述佣工的第二位。

If using sign_in already works for you but leaves the user on a blank page, check your logfile to see if there is a redirect going on, and where it redirects to. Or just make the redirect explicit by using the second of the helpers above.

这篇关于如何调用来自不同色器件另一个控制器设计色器件sign_in和SIGN_OUT方法呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆