我希望我的 2.3 Rails 应用程序中的所有页面的 url 前缀为:
www.example.com/app/
我在
routes.rb
中写了这篇文章以下几行:# I named the first part of the url ':appl'
map.root :appl => "app", :controller => "home"
# Default routes
map.connect ':appl/:controller/:action/:id'
map.connect ':appl/:controller/:action/:id.:format'
一切正常,除了
map.resources
,我有map.resources :pages
现在无论我在哪里
edit_page_path
或 page
, 生成的 url 不正确,因为 app
没有在开头插入。我试过 namespace
和 scope
,就像我见过的 here in chapter 2.6 ,但没有成功。我该怎么做?是
:appl
在 route 是个坏主意?
最佳答案
如果您在乘客上部署,您只需要设置(在您的网络服务器配置中):RailsBaseURI /app
然后在您的应用程序配置中:
config.action_controller.relative_url_root = '/app'
您不需要担心除此之外的任何子 uri 内容。它应该可以正常工作。见 Passenger documentation更多细节。
对于杂种,您可以使用 --prefix 选项
script/server mongrel -P /app
关于ruby-on-rails - Rails 应用程序中的前缀 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4707896/