简体   繁体   English

在局部中使用路径帮助器会在Rails 3中生成错误的路径

[英]Using path helper in partials generate wrong path in rails 3

I have my application " http://www.example.com/test ". 我有我的应用程序“ 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 为了提供链接地址,我使用了Rals路径助手,如下所示

 profile_path(:id => whatever_id)

The issue is the generated url is like this:- 问题是生成的URL是这样的:

 /profile/whatever_id

It completely skips the app name which is "test". 它完全跳过了名为“ 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. 如果应用程序是使用/ Passenger Apache / Nginx模块安装在/ test下的,则Rails应用程序将使用服务器端前缀,并将自动生成正确的URL,只有开发环境才会在根范围内生成url。

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: 如果您的应用程序是独立运行或通过代理安装程序运行(如果前端Web服务器是Nginx服务器,则是典型安装程序),而您想在前缀路径下运行它,则必须使用如下scope方法:

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

See detailed info in the documentation . 请参阅文档中的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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