Forum: Ruby on Rails how to create test data using migration for file_column

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
32e165d7d11c5d643f1a76ccd7dd23ff?d=identicon&s=25 Cedric Ced (casensio)
on 2008-10-13 05:19
Hi,

i would like to create test data for my client using migration.

for example:
Model.create(
:name => 'john',
:age => '28'
)

how would one do that for the file_column "image" field? i have tried to
give the name of the file XXXX.jpg, but i get the following error
message:

"Do not know how to handle a string with value 'XXXXX.jpg' that was
passed to a file_column. Check if the form's encoding has been set to
'multipart/form-data'."

thanks a lot
883c3f1191ae15da9001b55ad2ad01e2?d=identicon&s=25 Alex Bartlow (alexbartlow)
on 2008-10-13 15:05
(Received via mailing list)
The easy way to display this is to just store the binary data of the
file.

So you'd have a blob column called image...

Model.create(
  :name => 'john',
  :image => File.read("/Path/To/Image/File/john.jpg")
)

Check out
http://www.mattberther.com/2007/10/19/uploading-fi...
for some image handling tips.


On Oct 12, 11:19 pm, Cedric Ced <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.