Forum: Ruby on Rails Questions about file_column plugin

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.
Szymon N. (Guest)
on 2006-03-16 22:36

I've got 2 models - let's call them User and Image. User has_many
images. (Thanks to Mark Reginal James :) ) I have a single form where i
can create a user and add to him any number of images, which are
uploaded using file_column plugin.

Now 3 questions:

1. How to change the default path where file_column plugin saves images,
so it will save them in a directory, which name is not image id, but
user id to which the image belongs to?

2. When user objects fails validation, but images were ok, i'd like to
display thumbnails of temporarly uploaded files by file_column, so that
user can see that they were acutally correctly uploaded. What is the
name of the variable in file_column that keeps path to the images and
how to access it from the view?

3. What is the best way to automatically delete files in the "tmp"
folder? It gets huge very quickly. I don't think that scheduling
deleting of these files is good solution, because user could be filling
his form while tmp folder is being deleted. Maybe i could somehow add a
callback that it will delete temporary image if it was succesfully
saved? But how? :)

That's all. Thanks in advance.
Szymon N. (Guest)
on 2006-03-17 12:02
It turned out that i wasn't using latest trunk version of file_column
plugin. New version solved above mentioned problems, but introduced a
new one.

If i specify dynamic default storage dir for images like this:

  file_column :name,
              :store_dir => :dynamic_dir

  def dynamic_dir

how can i later access images using url_for_file_column method? It seems
to be ignoring :store_dir option.
Dorian M. (Guest)
on 2006-03-17 17:17
(Received via mailing list)
you could schedule deletion of files that were 24hrs+ old in unix with
something like this:

find /full/img/path/tmp/ -type d -mtime -1 -exec rm -r {};

so, find in the path things of type 'directory' 1 day old (at least)
then rm -r each directory.
(you should probably test that :) )

not sure about the other bits...
This topic is locked and can not be replied to.