Re: validates_associated trouble

Alfredo Gama
Wed, 21 Feb 2007 16:04:20 -0000

Mark Reginald James wrote:
> Alfredo Gama wrote:
>
>>> Use validates_presence_of instead of validates_associated.
>>
>> the problem is that in some cases an Animals has not father or mother,
>> then how can i do it??
>
> This should allow clones if your foreign_keys are default NULL:
>
> validates_presence_of :sire, :if => Proc { |animal| animal.sire_id }
> validates_presence_of :dam,  :if => Proc { |animal| animal.dam_id  }
>
> If instead they''re default 0, the condition becomes
>
>     animal.sire_id > 0
>
> etc.
>
> --
> We develop, watch us RoR, in numbers too big to ignore.

THanks a lot for your help,

what is Proc?? i have to write the Proc method??

i newbie in RoR sorry