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
Test Driven Ajax (on Rails) [Book]
“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.