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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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.
On Jul 1, 4:50 pm, "Phlip"
<phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---