Saturday, 15 May 2010

Rails: How to receive errors from nested models -


I am trying to validate the email given to the CSV list of emails. That's why I have created the invent_list virtual feature where a list of email is given, it will loop and create a new record in invite_onele_email model.

Now the thing is fine, but how can I get the verification error thrown by InvitedOnlyEmail while looping in the user model so that I can use that error in the controller?

This is my main model:

  class users & lt; ActiveRecord :: Base attr_accessor: invite_list attr_accessible: invite_list has_many: invite_only_emails def invite_list = (list) list.split (","). Every do Addresses | Self.invited_only_emails.create! : Email = & gt; Address expired enddef invite_list self.invited_only_emails.map {| Email | Email.email}. Insert (',') End End   

And this is an invited_online model:

  inviting email inviting email & lt; ActiveRecord :: Base attr_accessible: email belong_to: user validates_format_of: email ,: with => /^([\w\.%\++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++ +> 

Thank you!

I think you can use the validates_associated method You can use:

  class users & lt; ActiveRecord :: base: validates_associated: invited_only_emails # ... end   



No comments:

Post a Comment