# File path inconsistency?

**URL:** <https://www.ruby-forum.com/t/file-path-inconsistency/108276>\
**Category:** Rails\
**Created:** [July 1, 2007, 4:09pm UTC](https://www.ruby-forum.com/t/file-path-inconsistency/108276 "2007-07-01T16:09:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [July 1, 2007, 4:09pm UTC](https://www.ruby-forum.com/t/file-path-inconsistency/108276/1 "2007-07-01T16:09:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [July 1, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/file-path-inconsistency/108276/2 "2007-07-01T17:51:43Z")

</div>

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]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [July 1, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/file-path-inconsistency/108276/3 "2007-07-01T19:49:57Z")

</div>

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.
