Rails 3 relative root url is not used in links

I have a rails 3.0.1 app hosted on www.example.com/v1

using Phusion Passenger. In my configuration, I have the following:

ENV['RAILS_RELATIVE_URL_ROOT'] = "/v1"

      

Rail apps load fine. The problem is with links on the page. Whenever I use link_to

with "/ some_path" as the url, the final url www.example.com/some_path

should be www.example.com/v1/some_path

.

Why link_to

doesn't it recognize my relative url root and include it when building links? How do I get around this?

Thank.

+3


source to share


2 answers


I have never done such routes before. Try this in a file routes.rb

:



scope "v1" do
  resources :some_resource
end

      

0


source


Try using link_to without the beginning of the forward slash

link_to "some_path"

      



Another way to deal with relative routes on the client side is to use the base tag

<html>
  <head>
    <base href="http://example.com/current/opened/page">

      

0


source







All Articles