Ruby on Rails:设计,想要添加邀请代码吗?
我想为用户注册添加一个邀请码要求。 IE。除了要求他们指定电子邮件/密码组合之外,我还想要一个附加字段:invite_code。这是一个临时修复,以便不需要的用户无法在给定的 alpha 期间登录。
我很困惑,因为 Devise 不添加控制器。我对虚拟属性的概念有点熟悉,我突然想到我可以向模型添加一个 :invite_code ,然后现在就硬编码一个步骤,其中指示邀请代码必须等于 12345 或目前的其他值。
这对于设备身份验证有意义吗?我该如何从正确的 Rails 宁静方法来解决这个问题?
非常感谢。
I would like to add an invite_code requirement for users to sign up. Ie. in addition to requiring them to specify an email/password combo, I want an additional field :invite_code. This is a temporary fix so that non-wanted users cannot login during a given alpha period.
I'm confused since Devise doesn't add controllers. I'm sort of familiar with the concept of virtual attributes, and it strikes me that I could add a :invite_code to the model, and then just hard code a step now where it says invite code must equal 12345 or whatever for now.
Does this make sense with devise authentication? And how do I go approaching this from a proper rails restful approach?
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1) 虚拟属性除了 getter 之外通常还需要 setter。
最简单的方法是添加
到用户模型
2) 我认为 Devise 希望用户模型进行验证。因此,您可以通过添加注释来停止验证
:added :on => :create 因为邀请代码仅用于创建新用户,而不用于更新。
1) A virtual attribute usually needs a setter in addition to a getter.
Easiest way is to add
to the User model
2) I presume that Devise wants the User model to validate. So you could stop the validation by adding
NOTE: added :on => :create since the invite_code is only needed for creating the new user, not for updating.
试试这个:http://github.com/scambra/devise_invitable
Try this: http://github.com/scambra/devise_invitable
根据文档,invitable 可以让你控制谁可以邀请其他人。如果
invitation_limit
设置为“0”,则人们无法分发邀请。来自文档:
According to the docs, invitable gives you control over who gets to invites others. People cannot distribute invites if there is a "0" setting for
invitation_limit
.From the docs: