Robert Mannl
2005-Jun-06 02:10 UTC
Website absolute path & url_for, link_to, image_tag etc
Hi! How can I make my Rails apps independant of the directory they reside in? I.e. on my local PC I might develop the app in: http://localhost/rails-app/public/ on the server I have the app in: http://www.someserver.com/some-subdir/ Hence I want my app to reference links always correctly, i.e. reference them by their absolute path. Now my problem: When I do: image_tag "/images/people/1.jpg" it returns http://localhost/rails-app/public/images/people/1.jpg --- that works fine However link_to "Link", "/images/people/1.jpg" returns http://localhost/images/people/1.jpg --- the /rails-app/public/ part is missing Is there some kind of constant that I can put into my link? E.g. link_to "Link", BASE_PATH+"/images/people/1.jpg" Thanks, Rob
Nicholas Seckar
2005-Jun-07 02:57 UTC
Re: Website absolute path & url_for, link_to, image_tag etc
Robert Mannl wrote:> How can I make my Rails apps independant of the directory they reside in?If you are using apache, then place a symlink to public/ in apache''s document tree. Rails will do all the work for you. If you''re using lighttpd, you can set relative_url_root in your config. Put something like this in one of you environments: class ActionController::AbstractRequest def relative_url_root() "/some/path" end end POPULATION EXPLOSION Unique in human experience, an event which happened yesterday but which everyone swears won''t happen until tomorrow. - The Hipcrime Vocab by Chad C. Mulligan