Reputation: 110960
I have the following in my user.rb:
validates :fname, :length => { :minimum => 1, :maximum => 100 }
validates :lname, :length => { :minimum => 1, :maximum => 100 }
How can I update this validations to only apply to existing users? I ask as I want to allow a user to signup without having to enter a fname or lname.
Ideas?
Upvotes: 2
Views: 2524
Reputation: 25029
You can also use :on => :update
, to make the validation only apply when a record is updated (as opposed to :on => :create
)
Upvotes: 3
Reputation: 107728
validates :fname, :length => { :minimum => 1, :maximum => 100 }, :unless => :new_record?
validates :fname, :length => { :minimum => 1, :maximum => 100 }, :unless => :new_record?
Upvotes: 6