Super Strange Ruby, or Rails, Non-Error -
given code block:
user.products.where(id: products.map(&:id)).update_all(test_field: "") products.each |product| if true product.test_field = "made it" product.save! end end product not saved! also, there no error. loop continues. in 7 years of working ruby, 3rd time have seen this, , have never figured out why occurs.
here unusual part. never mind moment gross update_all statement. if add together 1 line above, looks this:
user.products.where(id: products.map(&:id)).update_all(test_field: "") products.each |product| if true product.test_field = "made it" product.save! puts '' end end then save occurs. it's jars loose. can't explain it. however, if change:
puts '' to just:
puts then save doesn't happen again. no error or nothing.
now if whack update_all statement , move update within loop each product, save happens fine without puts ''.
has ever come across this? ruby-1.9.3-p545, rails 3.2.16, have had happen 2 other times in past 4 years.
i have run issue 1 time without 'real' solution, able work around it:
change
product.test_field = "made it" to
product.update_attributes!(test_field: "made it") and should prepare issue. although agree comments should study rails team, don't have motivation so.
ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.2
No comments:
Post a Comment