开发者

Rails Password Validate only in certain cases

In my rails 3 application, I have a user sign up form. I have it require and validate the password for signing up, however, if a user connects using omniauth, I cannot retrieve their password which brings me to my question. How can I make it so the password field does not get validated in certain cases?

I am aware that I can do user.save(:validate => false), but that开发者_运维问答 takes off all the validations.

P.S. i watched railscasts episode 235 & 236, however Ryan Bates does it with Devise, and I am doing it with my own login system.


You can write your own validation for password with a check if the user is using oauth.
Check this method: validate(*args, &block)


you can add conditions to the validation in the model:

validates_presence_of :password, :unless => :account_from_omniauth?

assuming you also define the method

def account_from_omniauth?
  true if //...your conditions
  false
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜