简体   繁体   English

序列化对象在我的开发框上工作正常,Heroku给出“TypeError(不能转储匿名类)”

[英]Serialized object works fine on my dev box, Heroku gives “TypeError (can't dump anonymous class Class)”

I may be using serialized objects wrong, so I apologize in advance. 我可能使用错误的序列化对象,所以我提前道歉。 For an activity feed, I'm using a serialized meta-data column to simplify the database call. 对于活动源,我使用序列化的元数据列来简化数据库调用。 Eg for the activity feed, I'm just pulling in Activity objects with the appropriate user_id. 例如,对于活动源,我只是使用适当的user_id拉入Activity对象。 I'm adding in the line_item object as seen here: 我正在添加line_item对象,如下所示:

class Activity < ActiveRecord::Base
  serialize :data

  activity = Activity.new(:user_id        => user_id...)

  if activity.source_type == "LineItem"
    line_item = LineItem.find(activity.source_id)
    activity.update_attributes(:data => line_item)
  end

Then I call it via some partials where "book" is the meta-data bit: 然后我通过一些部分调用它,其中“book”是元数据位:

= link_to image_tag(item.data.book.image_url),
    book_path(item.data.book.id)

This works fine on my box, but Heroku gives me "TypeError (can't dump anonymous class Class)". 这在我的盒子上工作正常,但Heroku给了我“TypeError(不能转储匿名类Class)”。 What gives? 是什么赋予了?

I think you need to explicitly say what type you are serializing to. 我想你需要明确说明你要序列化的类型。 So the syntax would be: 所以语法是:

serialize :data, Hash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM