Ticket 11394 adds the merge! method to any ActiveRecord::Errors object. If anyone has time to review the ticket and post their comments on if they like the idea of having this functionality: http://dev.rubyonrails.org/ticket/11394 Examples: person.errors.merge address.errors person.errors.merge address.errors, :only => [ :city, ;state ] person.errors.merge address.errors, :except => [ :street, :zip ] Thanks, Zach Dennis http://www.continuousthinking.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 -~----------~----~----~----~------~----~------~--~---
zdennis
2008-Mar-27 14:13 UTC
Re: Ticket #11394, Adding ActiveRecord::Errors#merge! method
Those examples should be "merge!" and not "merge" Zach Dennis http://www.continuousthinking.com On Mar 27, 9:11 am, zdennis <zach.den...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ticket 11394 adds the merge! method to any ActiveRecord::Errors > object. If anyone has time to review the ticket and post their > comments on if they like the idea of having this functionality: > > http://dev.rubyonrails.org/ticket/11394 > > Examples: > person.errors.merge address.errors > person.errors.merge address.errors, :only => [ :city, ;state ] > person.errors.merge address.errors, :except => [ :street, :zip ] > > Thanks, > > Zach Dennishttp://www.continuousthinking.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 -~----------~----~----~----~------~----~------~--~---
I think the example is too contrived. That particular situation you would/could solve using errors_for ''person'', ''address''. A better example would be something that uses delegation. class ZipCode < ARec::Base has_many :addresses validates_presence_of :city, :state, :zip end class Address < ARec::Base belongs_to :zip_code validates_presence_of :street validates_associated :zip_code [:city, :state, :zip].each do |delegated_attribute| delegate delegated_attribute, "#{delegated_attribute}=", :to=>:zip_code end def initialize(*attrs) params = attrs.last.is_a?(Hash) ? attrs.last : {} self.zip_code = params[:zip_code_id].nil? ? ZipCode.new : ZipCode.find(params[:zip_code_id]) super end end home = Address.new :street=>''123 Main St'', :city=>''Anytown'', :state=>''SC'' home.valid? #=> false In this scenario it would be helpful to merge the errors from home and home.zip_code since they appear to be one object to the user. On Mar 27, 10:11 am, zdennis <zach.den...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ticket 11394 adds the merge! method to any ActiveRecord::Errors > object. If anyone has time to review the ticket and post their > comments on if they like the idea of having this functionality: > > http://dev.rubyonrails.org/ticket/11394 > > Examples: > person.errors.merge address.errors > person.errors.merge address.errors, :only => [ :city, ;state ] > person.errors.merge address.errors, :except => [ :street, :zip ] > > Thanks, > > Zach Dennishttp://www.continuousthinking.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 -~----------~----~----~----~------~----~------~--~---