Forum: Ruby on Rails using attachment fu in masse

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
holden (Guest)
on 2009-05-31 20:37
(Received via mailing list)
I'm trying to use attachment fu to add a large number of images at
once using a script but i can't even get it to add an image from the
console... the other documentation i've found no longer seems to work.

Something like this doesn't work properly

c =
c.content_type = 'image/jpeg'
c.filename = 'test.jpg'
c.discussion_id = 7330
c.uploaded_data ='/Users/holden/Desktop/pictures/

It does save.. but the file doesn't get populated.

All the previous documentatio circa 2007 says :temp_file but this is
no longer available to i tried switching it to :uploaded_data, but
that doesn't seem to work either....

also it want's the size and is a required field, but shouldn't this be
automatically deduced.. providing it doesn't help either...

Any suggestions would be a great help,


holden (Guest)
on 2009-06-01 00:53
(Received via mailing list)
Something like this almost work...
(:name=>"test2", :location_id=>"1036", :image_attributes=>
[{ :uploaded_data=>"/Users/holden/Desktop/pictures/
LionsFW.jpg") }], :website=>"testdsfdf", :geo=>"", :phone=>"test",
:blurb=>"testdsfsdfsdf", :address=>"test", :hwID=>"test",

undefined method `[]' for #<File:/Users/holden/Desktop/pictures/
Maurício L. (Guest)
on 2009-06-01 01:23
(Received via mailing list)
Here's how I'm doing it:

        file = data ) #this is
the real data
        file.instance_variable_set( '@original_filename',
"#{rand(1000)}_#{filename}" )
        file.content_type = i.content_type

        i.uploaded_data=( file )!

Maurício Linhares (pt-br) |
holden (Guest)
on 2009-06-01 13:24
(Received via mailing list)
I tried using data )

and it does create the files... but the images don't work.

Is data supposed to be the filepath?  ie. photos/joe.jpg ?

I also found an example of exactly what I want to do in the Practical
Rails Plugins book, but which is outdated using "temp_data ="  It
looks simple and perfect, what am I missing?

On May 31, 11:22 pm, Maurício Linhares <removed_email_address@domain.invalid>
Franco C. (Guest)
on 2009-06-01 16:47
(Received via mailing list)
You can try with the example in the attachment_fu home (http://

i.uploaded_data =,


Franco C..
holden (Guest)
on 2009-06-01 17:02
(Received via mailing list)
nevermind found this lurking in the documentation... i suppose i
should have read it better before looking else where... ;-(

#!/usr/bin/env ./script/runner

# required to use ActionController::TestUploadedFile
require 'action_controller'
require 'action_controller/test_process.rb'

path = "./public/images/x.jpg"

# mimetype is a string like "image/jpeg". One way to get the mimetype
for a given file on a UNIX system
# mimetype = `file -ib #{path}`.gsub(/\n/,"")

mimetype = "image/jpeg"

# This will "upload" the file at path and create the new model.
@attachable = =>, mimetype))
This topic is locked and can not be replied to.