I have a question regarding reporting of errors for models which contain other models. For example, if I have a User model which contains a Comments collection, and I am not able to see any errors encountered when validating the comments. So if I do something like the following to append a new comment: user = User.find(id) comment = Comment.new(:comment => params[:comment_text], :user_id => id) user.comments << comment user.save! When I do this, with an empty :comment_text string, I get an exception (coming from a validates_length_if associated with the Comment model). My question is, how can I get this to show on the form via <%error_messages_for... %>, nicely formated instead of an application exception error message? At the moment I have a <%= error_messages_for :user %>, which results in a nicely formated page showing any validation errors for User. But not if an empty comment is added to the user''s comments collection. Any help would be greatly appreciated. Cheers, Diego --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nick Snels
2007-Feb-16 07:18 UTC
Re: Getting nicely formated error page for associated models
Hi Diego, take a look at http://railsforum.com/viewtopic.php?id=717 , that should provide a solution to your problem. Kind regards, Nick Snels -- http://www.railshostinginfo.com Compare Rails hosting companies -- 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 -~----------~----~----~----~------~----~------~--~---
Nick, thanks for the reply. Appreciate it. On Feb 16, 6:18 pm, Nick Snels <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> HiDiego, > > take a look athttp://railsforum.com/viewtopic.php?id=717, that should > provide a solution to your problem. > > Kind regards, > > Nick Snels > --http://www.railshostinginfo.com > Compare Rails hosting companies > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---