vimal wrote:
> So, is there anyother way to carry this out of the box
I'm not sure precisely what you're trying to accomplish here, but from
what I can tell it would probably be a lot simpler and more flexible to
use the built-in serialization provided by ActiveRecord:
------------------
serialize(attr_name, class_name = Object)
If you have an attribute that needs to be saved to the database as an
object, and retrieved as the same object, then specify the name of that
attribute using this method and it will be handled automatically. The
serialization is done through YAML. If class_name is specified, the
serialized object must be of that class on retrieval or
SerializationTypeMismatch will be raised.
Parameters:
attr_name - The field name that should be serialized.
class_name - Optional, class name that the object type should be equal
to.
Example
# Serialize a preferences attribute
class User
serialize :preferences
end
------------------
Using this technique you can save you Array object to a string field and
get back an Array object automatically. All you have to do is add the
serialize line in your model as shown above.
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---