Hello,
I have provider and patient models which both are belongs_to contact. On the provider and patient edit forms i use fields_for :contact to render associated contact fields.
The problem is in that i want to use different validation rules for provider.contact and patient.contact objects, i.e. i want to validate presence of contact's first_name in patient edit form, but i don't want to validate presence of first_name in provider edit form.
I tried to add dynamic validation rule in patient model:
validate :contact_first_name_blank
def contact_first_name_blank
errors.add('contact[first_name]', 'can not be blank') if contact.first_name.blank?
end
It adds error message in case of empty first_name field, but it does not hightlights contact[first_name] field.
Please help me resolve this problem, may be there is better way to do such validations.