0

I have the following code in my controller

@current_chat = current_user.sent_messages
                         .where("created_at > ? and receiver_id = ?", current_user.current_sign_in_at, current_chat[:receiver_id].to_i)
                         .select("body, created_at").each { |message| message.instance_eval { def type; @type end; @type = 'sent' } }

And I'm passing the @current_chat object to a partial like so:

<%= render partial: 'shared/chat_form', locals: { messages: @current_chat } %>

But I'm getting the following error:

singleton can't be dumped

At the first line in ActiveSupport::MessageVerifier#generate

def generate(value)
  data = ::Base64.strict_encode64(@serializer.dump(value))
  "#{data}--#{generate_digest(data)}"
end

Any ideas on how to fix this?. Thanks in advance.

Akshay Takkar
  • 500
  • 1
  • 7
  • 21

1 Answers1

0

You can not use this

@serializer.dump(value)

This is causing the error. Read this link, its all about using singletons in ruby. link

Syed Farjad Zia Zaidi
  • 3,302
  • 4
  • 27
  • 50
  • I'm not using it.This is rails source code. I've mentioned the module and class in the question. Any way to avoid it? – Akshay Takkar May 19 '14 at 13:24
  • Once you’ve created a singleton class for an object you can no longer use Marshal.dump on that object. The marshal library does not support objects with singleton classes. – Syed Farjad Zia Zaidi May 19 '14 at 13:29
  • Actually, I want to 'tag' the records returned by the query `current_user.sent_messages` as 'sent'. Any idea how to do this without using instance_eval? – Akshay Takkar May 19 '14 at 13:35