File path inconsistency?

Hi all,

i am a beginner of ROR. please excuse me if i ask newbie questions.

i use Netbeans 6 as my IDE. i keep some of my image files under public/
images/

my question is:

in the controller the images files’ path is “/public/images/”, but in
View the path becomes “/images/”, why?

Thanks.

Mister Yu wrote:

in the controller the images files’ path is “/public/images/”, but in
View the path becomes “/images/”, why?

Because the former is the path relative to RAILS_ROOT on your file
system,
and the latter is the path as part of an URI (an URL).

The Rails way to handle the latter is always thru image_path() or
image_tag(). Don’t get in the habit of hard-coding the /image/ part -
just
say image_path(‘myImage.png’).


Phlip
http://www.oreilly.com/catalog/9780596510657/
“Test Driven Ajax (on Rails)”
assert_xpath, assert_javascript, & assert_ajax

Thanks Philip for the reply.

how to avoid hard-coding the path in controller? for example, i need
to write something like this:

if File.exist?("/public/images/abc.png")
do some stuff here
end

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs