File_column and HABTM

I have several models that will be using file_column by way of the
“Picture” class (HABTM). Right now, all pictures are stored in:

public/picture/image/1/filename1.jpg
public/picture/image/2/filename2.jpg

Is there a way I can dynamically define the “store_dir” based on the
model? For example, if I have “user”, “product” and “place” models all
of which HATBTM “picture”, I’d like uploads to be located in:

public/picture/user/1/filename.jpg ## user pic
public/picture/product/6/filename.jpg ## product pic
public/picture/place/102/filename.jpg ## place pic

(…or someplace similar, organized by model).

Is this concept possible?

Thanks
Adam.

Kyle

Thanks a lot! You’re always helpful. One more thing… setting the
store_dir does what I want, almost. With this I can set the path prefix,
but for the id, it’s still using the id from the “Picture” class. Is
there a way I can have this use the id from the user, place, profile,
etc… class insstead?

Upload goes to:

picture/user/PICTURE_ID/filename

can I set it to go to:

picture/user/USER_ID/filename (if I know I’m dealing with the “user”
class, etc… )

Thanks for all your help
Adam.

Fair enough. Two more quick ones.

I’m using store_dir => :my_store …which saves the files in the right
location, but url_for_image_column seems to be disregarding this. For
example, I’m telling store_dir to use ‘/pictures/user’, but
url_for_image_column is still looking in ‘/picture/filename’.

Second, I’m using Switchtower to manage deployment. My pictures are
stored in /pics, but I don’t want pictures in svn. Each new release is
deployed with an empty /pics dir, and I have to copy over the pictures
manually. Do you have a suggestion for dealing with this? Can
file_column store pictures in a directory outside of RAILS_ROOT without
much trouble (didnt seem like the helpers would adapt to this
situation), or maybe I should just use a symlink.

Thanks
Adam.

On 12/22/05, aroth [email protected] wrote:

public/picture/user/1/filename.jpg ## user pic


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

class Picture
file_column :image, :store_dir => :my_method

def my_method
if products.length > o
“picture/user”
elsif #…
end
#…


Kyle M.
Chief Technologist
E Factor Media // FN Interactive
[email protected]
1-866-263-3261

On 12/23/05, aroth [email protected] wrote:

picture/user/PICTURE_ID/filename
Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

I would imagine that to require a source patch. I would suspect that
you’re putting too much thought into this. I’d just use it as it
works, or, if you’re converting a legacy structure, write a simple
ruby script to restructure your files.


Kyle M.
Chief Technologist
E Factor Media // FN Interactive
[email protected]
1-866-263-3261

On 12/25/05, aroth [email protected] wrote:

Second, I’m using Switchtower to manage deployment. My pictures are
stored in /pics, but I don’t want pictures in svn. Each new release is
deployed with an empty /pics dir, and I have to copy over the pictures
manually. Do you have a suggestion for dealing with this? Can
file_column store pictures in a directory outside of RAILS_ROOT without
much trouble (didnt seem like the helpers would adapt to this
situation), or maybe I should just use a symlink.

symlink to the shared directory. switchtower can do the linking for
you.

Did you solve the first issue?

Kind regards
Mam