Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 952783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:56:58+00:00 2026-05-15T23:56:58+00:00

I have a db column which is a serialized Hash : class Foo <

  • 0

I have a db column which is a serialized Hash:

class Foo < ActiveRecord::Base
   serialize :bar
end

When I store a hash inside of bar that is a few levels deep, the deeper levels do not seem to properly deserialize when I need them. Objects one level deep get deserialzed just fine. However, objects 2 or more levels deep remain YAML classes.

I tried manually deserializing using YAML::load() but got an error saying the argument wasn’t an instance of IO.

Does anyone know why the complete Ruby object doesn’t deserialize?

EDIT: After further investigation, the problem seems to stem from the fact that I’m calling a virtual attribute from the serialized YAML.

class Foo < ActiveRecord::Base
   serialize :bar
end

class Bar < ActiveRecord::Base
    attr_accessor :enabled
end

@bars = @foo.bar[:bars]
@bars.each do |bar|
   puts bar.enabled
end

yields:

NoMethodError: undefined method `enabled' for #<YAML::Object:0xb6f11844>
    from (irb):12
    from (irb):11:in `each'
    from (irb):11
    from :0

Does this mean deserialization isn’t “real”, ie, the YAML object acts similar to the original object, but it’s not an actual instance of that object?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:56:58+00:00Added an answer on May 15, 2026 at 11:56 pm

    There’s two things to keep in mind when serializing user-defined objects instead of “plain old Ruby” objects.

    • You need to have the user-defined classes loaded before the object can be properly de-serialized or the instances will be of a generic YAML::Object type. De-serializing does not auto-load classes.
    • Some objects may not properly serialize without some customization, though this is generally not the case.

    Generally serializing instances of an ActiveRecord::Base object is a bad idea as these have an extraordinary amount of baggage that will need to be encoded in addition to your attribute. It is best to build a class that is derived directly from Object, which is the default behavior, or from a simple base class of some sort.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an options column which is serialized. I plan to store user preferences
For example, Lets say that I have a gridview column which has important controls,
I have a Moose class that i would like to store using Apache::Session::File. However,
I have column in mysql DB which contains serialized data (used PHP JSON encode
I have a table in which I need to store some serialized json strings
For each row I have a column which contains numbers like this 1,4,6,3,16,13 .
Hi I an issue with editors in a JTable. I have a column which
I have an xml column which contain data like this: <AuthorList CompleteYN=Y> <Author ValidYN=Y>
I have a property column which can have a subset of the following values
How can I find all column values in a column which have trailing spaces?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.