I want to append to my models error collection from another models errors like: @user.errors each do |e| @post.errors << e end unless @user.valid? But it says: ''undefined method << for activemodel post ..... What is errors then, a hash? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
puts, awesome print, pry, ruby-debug are all great tools you might try before bringing this up on the list: Try: @user.errors each do |e| puts @post puts @post.errors puts @post.errors.class @post.errors << e end unless @user.valid? then run your test again. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/BU2OGbogZHYJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 February 2012 03:48, S Ahmed <sahmed1020-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want to append to my models error collection from another models errors > like:Have a google http://www.google.co.uk/search?q=rails+merge+errors You don''t say what version of Rails you''re using, but historically I have posted up a solution for 2.3.x -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Assuming both instance vars have bene instantiated correctly previously... @user.errors.each { |k,v| @post.errors.add(k, v) } if @user.errors.any? should do it. HTH, Dan On Feb 23, 10:48 pm, S Ahmed <sahmed1...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want to append to my models error collection from another models errors > like: > > @user.errors each do |e| > @post.errors << e > end unless @user.valid? > > But it says: > > ''undefined method << for activemodel post ..... > > What is errors then, a hash?-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.