How do you deal with multiple objects in error_messages_for when one or more may be nil? For example: <%= error_messages_for :object => [@account, @account.billing_detail, @account.mailing_address, @account.billing_address] %> Here, @account.billing_detail may be nil, and throw a NoMethodError. Thanks, Mark -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Now, is @account a variable or a class? I could be way off in left field, but it looks like your calling objects that should be from a class. Variables should only be called by themselves typically. On Oct 15, 3:59 pm, Mark Richman <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> How do you deal with multiple objects in error_messages_for when one or > more may be nil? > > For example: > > <%= error_messages_for :object => [@account, @account.billing_detail, > @account.mailing_address, @account.billing_address] %> > > Here, @account.billing_detail may be nil, and throw a NoMethodError. > > Thanks, > Mark > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
@account is an instance of class Account. Account has_one BillingDetail Account has_one MailingAddress Account has_one BillingAddress My issue is how to deal with nil references on the has_one associations. To my knowledge, the above syntax is the only way to deal with error messages in a multi-model form. I could have also done this: <%= error_messages_for :object => [@account, @billing_detail, @mailing_address, @billing_address] %> having set these class variables in the controller, but that does not solve the nil issue. Thanks, Mark -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Richman wrote:> How do you deal with multiple objects in error_messages_for when one or > more may be nil? > > For example: > > <%= error_messages_for :object => [@account, @account.billing_detail, > @account.mailing_address, @account.billing_address] %> > > Here, @account.billing_detail may be nil, and throw a NoMethodError. > > Thanks, > Marki don''t know why you are trying in this way anyway try this <%= error_messages_for :object => [@account, @account.billing_detail, @account.mailing_address, @account.billing_address].compact %> by mokkai -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That worked! Thank you...had no idea you could do that...guess I should learn more Ruby :)> anyway try this > <%= error_messages_for :object => [@account, @account.billing_detail, > @account.mailing_address, @account.billing_address].compact %> > > by > mokkai-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Richman wrote:>had no idea you could do that...why ? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sniper Abandon wrote:> Mark Richman wrote: >>had no idea you could do that... > why ?Why did I have no idea?? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---