how to append to models errors collection?

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?

puts, awesome print, pry, ruby-debug are all great tools you might try before bringing this up on the list:


@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.

Have a google

You don't say what version of Rails you're using, but historically I
have posted up a solution for 2.3.x

Assuming both instance vars have bene instantiated correctly

@user.errors.each { |k,v| @post.errors.add(k, v) } if

should do it.