Forum: Ruby on Rails Filecolumn storage location

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.
188a96403bfb1b3781ab95fc1bc92241?d=identicon&s=25 Jordan Elver (Guest)
on 2006-03-23 14:39
(Received via mailing list)
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
Cc0720e5d9c3f0fef2121efe512e754d?d=identicon&s=25 ettober (Guest)
on 2006-03-23 15:45
(Received via mailing list)
Hi,
did you checked permissions?

--
View this message in context:
http://www.nabble.com/Filecolumn-storage-location-...
Sent from the RubyOnRails Users forum at Nabble.com.
188a96403bfb1b3781ab95fc1bc92241?d=identicon&s=25 Jordan Elver (jordelver)
on 2006-03-23 16:09
(Received via mailing list)
> 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
Ec30a6fd730b3c7788b59409ed568e7a?d=identicon&s=25 Justin Blake (Guest)
on 2006-03-24 13:53
(Received via mailing list)
On 3/23/06, Jordan Elver <jordan.elver@gmail.com> 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
F639e0cdf2fa098b535d6ec766b2aee1?d=identicon&s=25 Szymon Nowak (g0nzo)
on 2006-03-24 14:25
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.
188a96403bfb1b3781ab95fc1bc92241?d=identicon&s=25 Jordan Elver (jordelver)
on 2006-03-24 17:53
(Received via mailing list)
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 :)

Cheers,
Jord
This topic is locked and can not be replied to.