开发者

How can one Validate presence of only one?

开发者 https://www.devze.com 2023-02-06 16:35 出处:网络
I have a user model that has_one signup. I\'m having a recurring bug where users will click multiple times and create many unnecessary si开发者_JAVA技巧gnups. How can I validate the user only gets on

I have a user model that has_one signup.

I'm having a recurring bug where users will click multiple times and create many unnecessary si开发者_JAVA技巧gnups. How can I validate the user only gets one? Is there a way to do that from the model?


Not sure about your model, but validates_uniqueness_of might be what you are looking for.


In rails 3 you could do like this.

validates :field, :uniqueness => true

If you want your custom message then

validates :field, :uniqueness => {:message => 'your message'}

0

精彩评论

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