Loading binary data from a file using ActiveRecord Create
1 answer
I was able to get this to work. Instead of doing:
MyTableObject.create(
:name => "Test",
:image => File.read("PathToMyFile.jpg")
)
which did insert a record into the database, but without the correct binary representation of the file
MyTableObject.create(
:name => "Test",
:image => File.open("PathToMyFile.jpg", 'rb').read
)
seemed to do the trick.
+1
source to share