Forum: Ruby on Rails url_for_file_column not returning correct path

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.
720fde074c77f4c9692dd6f05802d581?d=identicon&s=25 Nithin Reddy (jashugan)
on 2006-03-02 21:20
(Received via mailing list)
I added this test towards the end of the included
file_column_helper_test.rb that shipped with the file_column plugin:

  def test_url_for_file_column_different_root_path
    Entry.file_column :image, :root_path => File.join(RAILS_ROOT,
"public/files")
    e = Entry.new(:image => upload(f("skanthak.png")))
    assert_match %r{/public/files/entry/image},
e.image_options[:store_dir]
    assert e.save
    assert_match %r{files/entry/image}, url_for_file_column(e, "image")
  end

the last assert_match did not pass...

  1) Failure:
test_url_for_file_column_different_root_path(UrlForFileColumnTest)
[file_column_helper_test.rb:59]:
<"/entry/image/1/skanthak.png"> expected to be =~
</files\/entry\/image/>.

The file is correctly stored in the :root_path specified. It's as if
url_for_file_column doesn't take it into account. Has anyone else
experienced this problem?
F719c6cb34bd5b691c12b373b7244b4d?d=identicon&s=25 Dorian Mcfarland (tachekent)
on 2006-03-03 15:58
the url wouldn't be using the rails_root because it's looking for a web
accessible path (URL), not the filesystem path.

maybe you need to use :store_dir instead?

Nithin Reddy wrote:
> I added this test towards the end of the included
> file_column_helper_test.rb that shipped with the file_column plugin:
>
>   def test_url_for_file_column_different_root_path
>     Entry.file_column :image, :root_path => File.join(RAILS_ROOT,
> "public/files")
>     e = Entry.new(:image => upload(f("skanthak.png")))
>     assert_match %r{/public/files/entry/image},
> e.image_options[:store_dir]
>     assert e.save
>     assert_match %r{files/entry/image}, url_for_file_column(e, "image")
>   end
>
> the last assert_match did not pass...
>
>   1) Failure:
> test_url_for_file_column_different_root_path(UrlForFileColumnTest)
> [file_column_helper_test.rb:59]:
> <"/entry/image/1/skanthak.png"> expected to be =~
> </files\/entry\/image/>.
>
> The file is correctly stored in the :root_path specified. It's as if
> url_for_file_column doesn't take it into account. Has anyone else
> experienced this problem?
720fde074c77f4c9692dd6f05802d581?d=identicon&s=25 Nithin Reddy (jashugan)
on 2006-03-03 21:03
(Received via mailing list)
On 3/3/06, dorian mcfarland <loaf@isness.org> wrote:
> the url wouldn't be using the rails_root because it's looking for a web
> accessible path (URL), not the filesystem path.
>
> maybe you need to use :store_dir instead?

I'm not sure how to use this option. I want the images stored in...

public/files/<model_name>/<attribute_name>/<id>, instead of
public/<model_name>/<attribute_name>/<id>

I've tried the following with no success (it just used the default
directory):

file_column(  :file_name,
                :options => {:mime_extensions => MIME_EXTENSIONS,
:store_dir => "files"},
                :magick => {:versions => {:small => {:crop => "1:1",
:size => "75x75"},
                                          :medium => {:crop => "1:1",
:size => "150x150"} } } )

I'm not sure what to set :store_dir as (I've tried a few different
combinations).
This topic is locked and can not be replied to.