Reputation: 37
I'm trying to add validations to just a specific page. right now I have a user put in their e-mail/pw/pw-confirmation when they sign up and after clicking submit it directs them to the users edit page.
I'm using the following line of code:
validates :first_name, :last_name, :date_of_birth, :goals, uniqueness: true, on: :edit
unfortunately it's not validating can someone help me explain why ?
Upvotes: 0
Views: 51
Reputation: 2088
Previous answer is a bit misleading. Problem with your code wasn't the validation syntax. You can still use
validates :first_name, :last_name, :date_of_birth, :goals, uniqueness: true
but instead of on: :edit
you should have on: :update
Upvotes: 0
Reputation: 945
The problem is you are trying to perform 'sexy validation' on multiple attributes at once. It won't work. try this instead:
validates_uniqueness_of :first_name, :last_name, :date_of_birth, :goals, on: :update
Upvotes: 1