Rails 2.3.2 bug? Detecting changed fields

I have a text field in the database, lets call it log. If I do
something like this:

x = MyModel.find(1)
x.log << “append some text”
x.save

Nothing is saved.

If I do something like this:

x = MyModel.find(1)
x.log += “append some text”
x.save

It works. Seems like a bug.

On Mar 31, 4:33 pm, Meech [email protected] wrote:

Nothing is saved.

If I do something like this:

x = MyModel.find(1)
x.log += “append some text”
x.save

It works. Seems like a bug.

See http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html - if you
change things inplace you need to use the foo_will_change! methods

Ah, I see.

Too much work, doesn’t feel like it’s my job to tell what’s changed
or will change.

I’ll just switch to +=

On further testing…

x = MyModel.find(1)
x.log << “append some text”

x.changed
=> []

x.log
=> “old valueappend some text”

The value is clearly changed in the resident copy of the model, yet it
doesn’t recognize it as changed.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs