开发者

How can one Validate presence of only one?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜