Reputation: 16339
I have two disabled textbox. And it's passing nil as value.
Still update_attribute is firing validation for those textboxes.
As per my knowledge update_attribute should not update the spefic column which has nil value passed.
validates_inclusion_of :text_response_time, :in => 0..60, :message => " should be between 0 to 60 minutes."
(rdb:589) params[:test][:text_response_time]
nil
(rdb:589) @test.update_attributes!(params[:test])
ActiveRecord::RecordInvalid Exception: Validation failed: Text response time should be between 0 to 60 minutes.
Any Idea!
Upvotes: 0
Views: 1205
Reputation: 18784
To further illustrate:
@test.update_attribute(:test, params[:test][:text_response_time])
will save without validation.
Another strategy that may work in your situation is to only validate on creation (and not updates):
validates_inclusion_of :text_response_time, :in => 0..60,
:message => "should be between 0 to 60 minutes.", :on => :create
Upvotes: 0