Filecolumn storage location


#1

Hi,
I am using file_column for some image uploading. I want to have all
the images stored under one root which I have managed by setting the
:store_dir option as below.

file_column :filename, :store_dir => File.join(RAILS_ROOT, ‘public’,
‘images’, ‘products’)

So, my images get uploaded to:

/public/images/products/<primary_key>

That’s fine. But none of my links to the images work.

What am I doing wrong?

Thanks,
Jordan


#2

Hi,
did you checked permissions?


View this message in context:
http://www.nabble.com/Filecolumn-storage-location-t1330285.html#a3552630
Sent from the RubyOnRails Users forum at Nabble.com.


#3

did you checked permissions?

The permissions look ok. Basically, I should of said before that the
url being generated is incorrect. The url_for_image_column generates
this:

/images/products/image/filename/9/thumb/PIC1083486196.jpg

When it should be this:

/images/products/9/thumb/PIC1083486196.jpg

So, the model and the attribute are being put into the url regardless.
I don’t know why though? Looking at the file_column helper code (I am
a newbie though), the model and attribute seem to get added to the url
regardless of if you set the :web_root or not.

Any more ideas?

Thanks for any help,
Jordan


#4

There also :base_dir option that may be useful for you, which if i
remember correctly is “:web_root + model_name + column”. You can
override it with “sub_dir/” and it should work.


#5

On 3/23/06, Jordan E. removed_email_address@domain.invalid wrote:

/images/products/9/thumb/PIC1083486196.jpg

So, the model and the attribute are being put into the url regardless.
I don’t know why though? Looking at the file_column helper code (I am
a newbie though), the model and attribute seem to get added to the url
regardless of if you set the :web_root or not.

Any more ideas?

I had the same problem. But I gave in and let the model and attribute
be in the path, but still got everything under one subdirectory by
passing:

:web_root => “sub_dir/”

and

:root_path => File.join(RAILS_ROOT, “public”, “sub_dir”)

Seemed kind of like a hack though…

Justin


#6

Thanks for the replies.

There also :base_dir option that may be useful for you, which if i
remember correctly is “:web_root + model_name + column”. You can
override it with “sub_dir/” and it should work.

I think you’re thinking of :base_url. I’ve just changed the file_column
line to:

file_column :filename, :store_dir => File.join(RAILS_ROOT, ‘public’,
‘images’, ‘products’), :base_url => File.join(‘images’, ‘products’)

So, the files are saved to the :store_dir location and the url to the
files is changed with :base_url to /images/products/.

Thanks for the pointers :slight_smile:

Cheers,
Jord