But is the validates_presence_of supposed to catch that first?

On Tuesday, March 8, 2011 9:33:40 PM UTC-6, jim wrote:
>
>
>
> On Wed, Mar 9, 2011 at 10:34 AM, Me <[email protected]> wrote:
>
>> Ok, well the value in the validates_each is giving me nil, not sure why.  
>> Error is:
>>
>> The error occurred while evaluating nil.>=):
>>
>> validates_presence_of :code
>> validates_uniqueness_of :code
>> validates_presence_of :valid_from_date, :expiry_date
>> validates_each :expiry_date do |record, attribute, value|
>>   record.errors.add(:expiry_date, 'must be after or the same as valid from 
>> date') unless value >= record.valid_from_date
>> end
>>
>>
> the error says that value is nil so check first if it's nil or not.
>
> validates_each :expiry_date do |record, attribute, value|
>   record.errors.add(:expiry_date, 'must be after or the same as valid from 
> date') if value && !(value >= record.valid_from_date)
> end
>  
>
>> On Tuesday, March 8, 2011 8:28:21 PM UTC-6, jim wrote:
>>>
>>>
>>>
>>> On Wed, Mar 9, 2011 at 10:19 AM, Me <[email protected]> wrote:
>>>
>>>> If you have:
>>>>
>>>> validates_presence_of
>>>> validates_uniqueness_of 
>>>> ...
>>>>
>>>> validates_each
>>>>
>>>>
>>>> What fires in what order?
>>>>
>>>
>>> the way you order them in your model file. so validates_presence_of goes 
>>> first,
>>> uniqueness next then validates_each.
>>>  
>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Ruby on Rails: Talk" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to 
>>>> [email protected].
>>>>
>>>> For more options, visit this group at 
>>>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>>>
>>>
>>>
>>>
>>> -- 
>>> -------------------------------------------------------------
>>> visit my blog at http://jimlabs.heroku.com
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>
>
>
>
> -- 
> -------------------------------------------------------------
> visit my blog at http://jimlabs.heroku.com
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to