Hello,
I have two virtual properties (schedule and diameter) that are saved
in the db as one property (diameter_schedule_id -> fk to another
model). When you set the properties in the model, they locate the
proper DiameterSchedule and save the id. The exception happens when
the selected schedule is not available for the chosen diameter. I
wrote a validator that correctly throws an error using
errors.add(:schedule, …). Although the validator works correctly, it
just raises a generic error, I would like it to highlight the field
and display the error (like it is supposed to?). Any ideas?
Thanks in advance
On Jun 16, 2008, at 11:17 AM, Trogdor wrote:
I have two virtual properties (schedule and diameter) that are saved
in the db as one property (diameter_schedule_id -> fk to another
model). When you set the properties in the model, they locate the
proper DiameterSchedule and save the id. The exception happens when
the selected schedule is not available for the chosen diameter. I
wrote a validator that correctly throws an error using
errors.add(:schedule, …). Although the validator works correctly, it
just raises a generic error, I would like it to highlight the field
and display the error (like it is supposed to?). Any ideas?
You can specify an error message
self.errors.add(:schedule, ‘A schedule for that diameter is not
available.’)
And then display that error just like you would for any built-in
validation error.
–
def gw
writes_at ‘www.railsdev.ws’
end
One other thing. The view renders forms for two different models. I
have a form_for for the parent and fields_for for the child. The child
is the one I am having trouble with, but when I put validation into
the parent, I get the same problem. <%= f.error_messages %> and <%=
fields.error_messages %> are in the appropriate spots as well.
That’s how I am doing it right now, the problem is that it won’t
display on the form (I have tried both self.errors.add and
errors.add).
could it be cause you have to use errors.add_to_base?
I’m guessing, but I think it might work.
Thanks for your help, but now it just ignores the error altogether.
I tried using errors.add(:field, “description”) in another controller
without a multi-model form and it worked as expected.