Forum: Ruby on Rails Rails 2.3.2 bug? Detecting changed fields...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Meech (Guest)
on 2009-03-31 19:34
(Received via mailing list)
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.
Frederick C. (Guest)
on 2009-03-31 19:37
(Received via mailing list)
On Mar 31, 4:33 pm, Meech <removed_email_address@domain.invalid> 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
Meech (Guest)
on 2009-03-31 19:44
(Received via mailing list)
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 +=
Meech (Guest)
on 2009-03-31 19:44
(Received via mailing list)
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 topic is locked and can not be replied to.