Forum: Ruby on Rails file_column and HABTM

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 aroth (Guest)
on 2005-12-23 06:18
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.
4bd34a2216dc8bdbf1f017f64e4d59e8?d=identicon&s=25 Kyle Maxwell (Guest)
on 2005-12-23 07:59
(Received via mailing list)
On 12/22/05, aroth <adamjroth@gmail.com> wrote:
> public/picture/user/1/filename.jpg  ## user pic
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> 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 Maxwell
Chief Technologist
E Factor Media // FN Interactive
kyle@efactormedia.com
1-866-263-3261
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 aroth (Guest)
on 2005-12-24 02:03
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.
4bd34a2216dc8bdbf1f017f64e4d59e8?d=identicon&s=25 Kyle Maxwell (Guest)
on 2005-12-24 02:25
(Received via mailing list)
On 12/23/05, aroth <adamjroth@gmail.com> wrote:
> picture/user/PICTURE_ID/filename
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> 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 Maxwell
Chief Technologist
E Factor Media // FN Interactive
kyle@efactormedia.com
1-866-263-3261
7a5ed48939fc288a4c70778140b203f6?d=identicon&s=25 aroth (Guest)
on 2005-12-26 02:01
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.
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2005-12-26 02:38
(Received via mailing list)
On 12/25/05, aroth <adamjroth@gmail.com> 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.
1112343d295a87e9143dab47a2b911c9?d=identicon&s=25 mam andersson (Guest)
on 2006-06-16 16:40
(Received via mailing list)
Did you solve the first issue?

Kind regards
Mam
This topic is locked and can not be replied to.