Selective validation? Is it possible?

Hello Petr,

I think this can be done. Here provided an example were a validation runs only for certain customer types.

validates_presence_of :birthday,                         :street,                         :street_number,                         :zip_code,                         :city,                         :bank_name,                         :bank_code,                         :bank_account,                         :telefon_number,                         :message => "darf nicht leer sein.",                         :if => Proc.new { | customer | customer.customer_type.name == "partner" or customer.customer_type.name == "customer" }

The important part for you is the :if part. Only for object that pass the test in the Proc the validation is used.

There is a "has_parent?" method for act_as_tree objects. I think this could be used for your problem...

Feurio

Hello Feurio,

There is a "has_parent?" method for act_as_tree objects. I think this could be used for your problem...

acts_as_tree defines a belongs_to association named 'parent', so you can benefit from a #has_parent? method. However this method is deprecated and you should use #parent (that is, the method with the name of the association), if there is no associated record, it returns nil then in a condition it will be false so you can use it.

Note that if you have a has_many :foos association, #has_foos? is also deprecated.

   -- Jean-François.