Trip
Trip

Reputation: 27114

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 signups. How can I validate the user only gets one? Is there a way to do that from the model?

Upvotes: 0

Views: 430

Answers (2)

kriysna
kriysna

Reputation: 6168

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'}

Upvotes: 1

Lennart Koopmann
Lennart Koopmann

Reputation: 836

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

Upvotes: 4

Related Questions