简体   繁体   中英

Using path helper in partials generate wrong path in rails 3

I have my application " http://www.example.com/test ". When I hit the url I get the index page, where I show list of profiles.

To show each profile in the lists, I have used a partial. Each of the profiles have link to their own show page.

To provide the link addreess I have used Rals path helper like this

 profile_path(:id => whatever_id)

The issue is the generated url is like this:-

 /profile/whatever_id

It completely skips the app name which is "test". The expected url by me is

 /test/profile/whatever_id

Can any one tell what can be the possible cause of this?

It is depends on what you means under "app name". If the app is mounted under /test with Passenger Apache/Nginx module, then Rails app will honor the server-side prefix, and will generate correct URLs automatically, only the development environment will generate urls in the root scope.

If your app is runs standalone or via proxy setup (typical setup if the frontend webserver is an Nginx server), and you want to run it under a prefixed path then you have to use the scope method like this:

Rails.application.routes do scope(:path => '/test') do # the rest of your routes go here end end

See detailed info in the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM