开发者

Why won't Rails deserialize my field?

开发者 https://www.devze.com 2022-12-09 17:56 出处:网络
I am using the Classifier:Bayes as part of a model class. I have the class set up to serialize the classifier to the db.

I am using the Classifier:Bayes as part of a model class. I have the class set up to serialize the classifier to the db.

class Foo < ActiveRecord::Base
  serialize :classifier
end

The yaml appears in the db just fine after doing some training and saving the object.

But when I query for the class, instance.classifier is a string

@f = Foo.find(params[:id])
@f.classifier.class   # is String

I was under th开发者_JAVA百科e impression that Rails / ActiveRecord would magically deserialize my classifier for me. Is there some setting I need to tweak or am I misunderstanding something?


In the past, I've had to add the class name to the method args...

class Foo < ActiveRecord::Base
  serialize :classifier, Classifier::Bayes
end
0

精彩评论

暂无评论...
验证码 换一张
取 消