Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Active Record Error in Rails 3.1

I'm upgrading an application from Rails 3.0 to 3.1 and found the following error showing up in my tests:

NoMethodError: undefined method `delete' for #<ActiveModel::Errors:0x007f928c0ee310>

I have the following snippet that moves errors :

after_validation do

  self.errors[:image_size].each do |message|
    self.errors.add(:image, message)
  end

  self.errors[:image_extension].each do |message|
    self.errors.add(:image, message)
  end

  self.errors.delete(:image_size)
  self.errors.delete(:image_extension)

end

I still need to be able to move all validations from image_size and image_extension, but I'm not sure how do this in Rails 3.1. Any ideas?

like image 573
Kevin Sylvestre Avatar asked Sep 06 '11 04:09

Kevin Sylvestre


1 Answers

The only method that removes anything is clear and the removes everything so I think you have to:

  • Pull all the error messages out (probably using to_hash).
  • Clear all the errors with self.errors.clear.
  • Put all the error messages back in the right/desired places using self.errors.add.
like image 134
mu is too short Avatar answered Nov 14 '22 23:11

mu is too short