views:

74

answers:

1

Is there an easy (or generally accepted) way to load up a binary column using the create method of ActiveRecord?

For example, what I'm trying to do is something similar to this:

MyTableObject.create :name => "Test", :image => File.read("PathToMyFile.jpg")
A: 

I was able to get this working. Rather than 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.

jerhinesmith