Forum: Ruby on Rails handling file upload onto local filesystem.

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.
Sam D. (Guest)
on 2006-05-09 08:01
(Received via mailing list)

I have a multipart form upload field uploaded through <%=
file_field("profile", "profile") %>

Once a submit happens, the action basically does something like:

profile =["picture"])

This invokes the models = to method:

def picture=(picture_field) a bunch of assignments here

def validate
  ... do a bunch of validations before saving

# do the actual file handling stuff here.
def after_save


My question is, is the after_save method the right place to put the File
manipulation stuff to copy and save the file on a directory on my local
webserver filesystem?   Also, how do I get access to the actual file in
after_save  so that I  could do stuff like the following:

file.local_path (basically work with the file object so that I could
copy it
over from its local path onto my filesystem)

and one more question, how do I pass stuff into this function that comes
from the controller but is not necessarily an attribute of the Profile

Thanks in advance.
Dorian M. (Guest)
on 2006-05-09 08:23
(Received via mailing list)
you could try using the file_column plugin.
makes things very easy to handle and you can do image processing (with
rmagick installed):

that's my easy answer...

Sam D. (Guest)
on 2006-05-09 09:42
(Received via mailing list)

I decided against the file_column plugin due to some limitations in how
have to access a file in a view using url_for_file_column.  Are there
other suggestions on my question, like on passing variables down to the
model from the controller?

This topic is locked and can not be replied to.