Astorian wrote:> In Agile Web Development with Rails, there is a section on serializing
> Ruby objects.
>
> "We can assign any Ruby object to the last_five column" ... p312
>
> When I attempt to do this with a proc object, something like this is
> saved in the db
>
> --- !ruby/object:Proc {}
>
> Obviously, this doesn''t do much, and I attempt to use it ...
>
> NoMethodError: undefined method `call'' for "---
!ruby/object:Proc {}\n
> \n":String
> from (irb):5
>
> Is it possible to save Proc objects in the db?
>
> I am implementing a custom field scheme, where users can create custom
> fields. I have Field Types, and I was thinking about using a ruby proc
> to convert field entries to the correct object type.
"any" must be taken with a grain of salt. Only objects that have a
serializable state can be saved that way. You couldn''t serialize a
thread, for instance, or in your case, a proc.
You can use Ruby2Ruby to get the source for a proc, then you can eval it
when you deserialize it to get an equivalent proc back. It may be easier
for you to store some other information in the db to do your custom
field converstion. What you are proposing sounds pretty unwieldy to me.
--
Josh Susser
http://blog.hasmanythrough.com
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---