Questions about file_column plugin


I’ve got 2 models - let’s call them User and Image. User has_many
images. (Thanks to Mark Reginal James :slight_smile: ) 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? :slight_smile:

That’s all. Thanks in advance.

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.

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 :slight_smile: )

not sure about the other bits…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs