如何在 Rails 3 中创建来宾用户 +设计
目前我有一个带设计的 Rails 3 应用程序。它要求用户注册/登录才能访问。
我想启用访客用户。这样,当用户访问某些视图时,就会为该用户创建一个访客用户帐户,然后如果/当他们验证/注册该访客用户时,该访客用户就会升级为普通用户。
将该应用程序视为聊天室。我希望访客用户能够加入聊天室,然后通过 oauth 进入 Twitter 进行注册。但我不想强迫用户在加入之前注册。
建议?
我发现了这个: https://github.com/ plataformatec/devise/wiki/How-To:-Create-a-guest-user
问题是我添加了帮助程序,但不明白如何启动 current_or_guest_user。还不确定如何启动每个特定允许的视图?
有什么想法吗?指针?谢谢
currently I have a rails 3 app with devise. it requires the users to register / signin for access.
I would like to enable guest users. So that when a user visits certain views a guest user account is created for that user and then if/when they authenticate/register that guest user is then upgraded to a normal user.
Think of the app as a chat room. I want guest users to be able to join the chat room, then later oauth into twitter to register. But I don't want to force users to register before joining.
Suggestions?
I found this: https://github.com/plataformatec/devise/wiki/How-To:-Create-a-guest-user
Problem with that is I added the helper, but don't understand how to initiate current_or_guest_user. Also not sure how to initiate per specific allowed views?
Any ideas? Pointers? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一种更透明的方式是:
Another more transparent way is this:
遵循 wiki 后,只需将对
current_user
的调用替换为current_or_guest_user
就视图而言,请在控制器中使用 before_filter 进行操作。
如果没有看到您的任何代码,很难猜测,但在伪代码中,它会类似于
After following the wiki, just replace calls to
current_user
withcurrent_or_guest_user
As far as views goes, do it in the controller with a before_filter.
Without seeing any code from you it is hard to guess, but in pseudo-code it would be something like
查看有关访客用户的此 Rails Cast。 5:40 左右有关 Devise 的详细信息。
Checkout this rails cast about guests users. Details about Devise at around 5:40.