J. Pablo Fernández
2012-Feb-15 10:15 UTC
Is there a way to skip serialization in Rails 3.1?
Hello, In my Rails 3.1 application, I need to read the raw data of a field, without serialization, and then write it down without serialization. Is this possible? How? By serialization I mean class Tenant serialize :profile_template end which I can access like this:> t.profile_template=> [{:title=>"Page 1", ....}] I tried several approaches, none of them worked. With read_attribute_before_type_cast:> t.read_attribute_before_type_cast(:profile_template)=> nil Using a string instead of a symbol had a different but disappointing result:> t.read_attribute_before_type_cast("profile_template")=> [{:title=>"Page 1", ...}] and same with the attribute name:> t.profile_template_before_type_cast=> [{:title=>"Page 1", ...}] Just for the record, what I was expecting is: "--- - :title: Page 1 ...." In all samples, ... is the rest of a very long structure. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/cuKrIn9asjYJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2012-Feb-15 19:09 UTC
Re: Is there a way to skip serialization in Rails 3.1?
On Feb 15, 2012, at 2:15 AM, J. Pablo Fernández wrote:> Hello, > > In my Rails 3.1 application, I need to read the raw data of a field, without serialization, and then write it down without serialization. Is this possible? How? > > By serialization I mean > > class Tenant > serialize :profile_template > end > > which I can access like this: > > > t.profile_template > => [{:title=>"Page 1", ....}] > > I tried several approaches, none of them worked. With read_attribute_before_type_cast: > > > t.read_attribute_before_type_cast(:profile_template) > => nil > > Using a string instead of a symbol had a different but disappointing result: > > > t.read_attribute_before_type_cast("profile_template") > => [{:title=>"Page 1", ...}] > > and same with the attribute name: > > > t.profile_template_before_type_cast > => [{:title=>"Page 1", ...}] > > Just for the record, what I was expecting is: > > "--- > - :title: Page 1 > ...." > > In all samples, ... is the rest of a very long structure.This is messy, but works... t.class.serialized_attributes[''profile_template''].dump(t.profile_template)> -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/cuKrIn9asjYJ. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.