Forum: Ruby on Rails serializing active record objects do not save after first slice

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.
Tyl T. (Guest)
on 2008-12-18 13:13
(Received via mailing list)
Hi,

i am having a very weird problem i have an array

Model:

serialize :marketarray


Controller
@marketobject = Market.find(1)

@marketobject.marketarray = ["red","blue","green"]

I do this @marketobject.marketarray.slice!(0)

@marketobject.save!

but it does not change the Market.marketarray to ["blue","green"]

it just keeps the original array as if it did not happen

if i do this @marketobject.marketarray = ["1","1"]
@marketobject.save!
then it saves the marketarray to ["1","1"]

please help.
Frederick C. (Guest)
on 2008-12-18 13:20
(Received via mailing list)
On 18 Dec 2008, at 11:13, tyliong wrote:
>
> but it does not change the Market.marketarray to ["blue","green"]
>
> it just keeps the original array as if it did not happen
>
> if i do this @marketobject.marketarray = ["1","1"]
> @marketobject.save!
> then it saves the marketarray to ["1","1"]
>
call @marketobject.marketarray_will_change! before you save (you must
do this when you change objects in place (so same thing if you had  a
string attribute and did .gsub!)

Fred
Tyl T. (Guest)
on 2008-12-18 13:25
(Received via mailing list)
Thanks Fred! That worked!
This topic is locked and can not be replied to.