ruby on rails - How do I work around a "RuntimeError: can't modify frozen Hash" when trying to delete records on Heroku? -


at rails console on heroku, trying simple array iteration , delete record if condition exists, , running error.

this doing:

irb(main):044:0> a.first => #<activity id: 1, trackable_id: 3, trackable_type: "node", owner_id: 5, owner_type: "user", key: "node.create", parameters: {}, recipient_id: nil, recipient_type: nil, created_at: "2014-07-30 11:22:15", updated_at: "2014-07-30 11:22:15", read_status: 0> irb(main):045:0> a.first.trackable.nil? => false irb(main):046:0> a.second.trackable.nil? => true irb(main):061:0> a.each |x| irb(main):062:1* if x.trackable.nil? irb(main):063:2> x.destroy irb(main):064:2> x.save irb(main):065:2> end irb(main):066:1> end runtimeerror: can't modify frozen hash 

thoughts on how can achieve this?

if leave off x.save doesn't rid of record seems.

you can't call .save on destroyed record. once you've called .destroy on record, it's been removed database already; there's no use calling .save on it. if you're basing determination of whether it's been destroyed whether still have access in ruby's memory, can call .destroyed? on record find out whether it's been destroyed or not.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -