简体   繁体   中英

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. I'm adding in the line_item object as seen here:

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:

= 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)". What gives?

I think you need to explicitly say what type you are serializing to. So the syntax would be:

serialize :data, Hash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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