1

I have a problem with serialization. In my model I have

class PramEntry < ActiveRecord::Base
  serialize :pram_units_array, Array
  attr_accessible :pram_units_array
end

then I do

entry = PramEntry.new
entry.pram_units_array = [PramUnit.new(depth: 1, width: 1)]

entry.pram_units_array 
=> [#<PramUnit:0x007fb368eb8ae8 @depth=1, @width=1>]
entry.save
=> true

but then I load this object from database

entry = PramEntry.first
entry.pram_units_array
=>  "---\n- &70364639756800 !ruby/object:PramUnit\n  depth: 1\n  width: 1\n  errors: !ruby/object:ActiveModel::Errors\n    base: *70364639756800\n    messages: !omap []\n  validation_context: \n"

it doesn't serializes it back from yaml. What I am doing wrong? Thanks in advance!

1 Answer 1

1

I found Answer to my question.

I've tried to deserialize manualy

YAML::load(PramEntry.last.pram_units_array)
=> ArgumentError: undefined class/module PramUnit

PramUnit is a ruby class in lib folder. I required it

require 'pram_unit'

even when I autoload files from lib.

 config.autoload_paths += Dir["#{config.root}/lib/**/"]

It was very strange behavior for me. But problem was resolved :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.