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?
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:
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.
On 24 February 2012 03:48, S Ahmed [email protected] wrote:
I want to append to my models error collection from another models errors
like:
Have a google rails merge errors - Google Search
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
previously…
@user.errors.each { |k,v| @post.errors.add(k, v) } if
@user.errors.any?
should do it.
HTH,
Dan
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs