gpt4 book ai didi

ruby-on-rails - Rails 应用程序中的前缀 url

转载 作者:行者123 更新时间:2023-12-04 18:52:03 32 4
gpt4 key购买 nike

我希望我的 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_pathpage , 生成的 url 不正确,因为 app没有在开头插入。我试过 namespacescope ,就像我见过的 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com