这是我的User
型号:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :token_authenticatable, :confirmable, :timeoutable,
:recoverable, :rememberable, :trackable, :validatable,
:email_regexp => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :confirmed_at, :confirmation_token, :category_ids
validates_uniqueness_of :email, :case_sensitive => false
validates_confirmation_of :password
end
我想要做的是强制实施&#39; category_ids&#39;在激活的&#39;帐户。
我正在做Email Only Sign-up - 这一点很重要,因为这是一个两阶段的过程。用户首次输入其电子邮件地址时,会向他们发送一封激活电子邮件,其中包含指向Confirmations
控制器的链接。
Confirmations Controller
的视图包含需要验证的其他详细信息。
如果我只是在validates_presence_of
型号上定期User
,那么当用户最初只提交一个电子邮件地址时 - Rails会失败(我不想要)。< / p>
用户应该:
步骤#3,Devise强制执行presence_of_validation for name&amp; PW。但不是我的自定义项category
。
我该怎么做?
感谢。
答案 0 :(得分:1)
您可以将:on => :update
选项传递给validates_presence_of
,但不会在创建时验证:
实施例
validates_presence_of :category_ids, :on => :update