This is my class:
class Articulo < ActiveRecord::Base
serialize :atributos_extendidos, Hash
def after_find
self.atributos_extendidos.each do |k,v|
Articulo.class_eval <<-CODE
def #{k}
self.atributos_extendidos ||= {}
self.atributos_extendidos[:#{k}]
end
def #{k}=(val)
self.atributos_extendidos ||= {}
self.atributos_extendidos[:#{k}] = val
end
CODE
end
end
end
And I try this in console:
>> a=Articulo.new(:atributos_extendidos => {:metros =>
"2",:habitaciones => "4"})
>> a.save!
>> a
=> #<Articulo id: 5, ... , atributos_extendidos:
{:metros=>"2",
:habitaciones=>"4"}>>> c=Articulo.find(5)
=> #<Articulo id: 5, ... , atributos_extendidos:
{:habitaciones=>"4",
:metros=>"2"} >>> c.habitaciones
=> "4">> c.metros
=> "2">> c.metros = "4"
=> "4">> c
=> #<Articulo id: 5, ... , atributos_extendidos:
{:habitaciones=>"4",
:metros=>"4"}>>> c.save!
=> true>> c
=> #<Articulo id: 5, ... , atributos_extendidos:
{:habitaciones=>"4",
:metros=>"4"} >>> c.reload
=> #<Articulo id: 5, ... , atributos_extendidos:
{:habitaciones=>"4",
:metros=>"2"}> # metros returns to "2"
Why I can''t save modified values in :atributos_extendidos? What am I
doing wrong?
Thanks
Juan MatÃas.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---