2

I have a mongoid document (in a rails app) that has failed validation. I want to reset all of the invalid fields. Currently I am doing this:

@product.errors.each do |e,m|
  method_name = "reset_#{e}!"
  @product.send(method_name)
end

This is ok, but is there not a better (more concise) way to do this? I've read the dirty tracking documentation and googled, but I can't find anything about this.

nashape
  • 733
  • 9
  • 13

1 Answers1

0

I don't know what do you mean with 'more concise' but you don't need use "send"

@product.errors.errors.each do |f|
  @product[f] = c.changes[f.to_s].first
end
kuadrosx
  • 391
  • 1
  • 5