2

I have a table defined with the following migration

create_table :posts, :force => true do |t|
    t.string :owner_name
    t.string :name
    t.binary :value
    t.timestamps
end

I'm trying to save some basic data types into the value column, but some data types are generating a "undefined method 'encoding'" message.

Integers, Floats and Symbols values fail. All that seems to work are string values. Does anyone know why this is happening? I thought the point of a blob column was it could be more general.

My goal is to have a column that can take multiple data types. Plan B would be to store the datatype name in it's own column and then type cast a string representation back when the data is retrieved, but I'd like to understand why the blog is failing.

3
  • Found anything yet? Having the same issue here.. Commented Jun 24, 2014 at 5:18
  • Unfortunately not. I ended up going with my plan B in this particular case. Commented Jul 14, 2014 at 22:43
  • In case it might still help for some reasons, check my answer. Commented Jul 15, 2014 at 0:18

1 Answer 1

1

This is what I was doing wrong (check this answer to my own question).

In comments there is also a link to a blog post which will get you started or at least give you a hint of what needs to be done when not going with CarrierWave or Paperclip gems for file uploads. It's not that hard... you just need to understand the reasons behind it.. and then forget them until you need this again.. (and so on.. until you can't forget them anymore ;) )

Hope it helps.

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.