Ruby on rails: Devise, want to add invite code?

試著忘記壹切 提交于 2019-11-28 16:34:58

1) A virtual attribute usually needs a setter in addition to a getter.

Easiest way is to add

attr_accessor :invite_code
attr_accessible :invite_code # allow invite_code to be set via mass-assignment
    # See comment by James, below.

to the User model

2) I presume that Devise wants the User model to validate. So you could stop the validation by adding

validates_each :invite_code, :on => :create do |record, attr, value|
    record.errors.add attr, "Please enter correct invite code" unless
      value && value == "12345"
end

NOTE: added :on => :create since the invite_code is only needed for creating the new user, not for updating.

Jeroen

Try this: http://github.com/scambra/devise_invitable

It adds support to devise for sending invitations by email (it requires to be authenticated) and accept the invitation setting the password.

It works with Devise >= 4.0 If you want to use devise 3.0.x, you must use 1.2.1 or lower If you want to use devise 3.1.x, you must use 1.3.2 or lower If you want to use devise >= 3.2, you must use 1.6.1 or lower...

Anne

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:

invitation_limit: The number of invitations users can send. The default value of nil means users can send as many invites as they want, there is no limit for any user, invitation_limit column is not used. A setting of 0 means they can't send invitations. A setting n > 0 means they can send n invitations. You can change invitation_limit column for some users so they can send more or less invitations, even with global invitation_limit = 0.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!