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 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On Jun 16, 2:17 pm, Trogdor <Trogdo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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). On Jun 16, 3:52 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
could it be cause you have to use errors.add_to_base? I''m guessing, but I think it might work. On Jun 16, 3:54 pm, Trogdor <Trogdo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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). > > On Jun 16, 3:52 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote: > > > 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--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On Mon, Jun 16, 2008 at 4:19 PM, sw0rdfish <santia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > could it be cause you have to use errors.add_to_base? > > I''m guessing, but I think it might work. > > On Jun 16, 3:54 pm, Trogdor <Trogdo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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). > > > > On Jun 16, 3:52 pm, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote: > > > > > 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 > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---