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

标签 ruby-on-rails routing

我希望我的 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/

相关文章:

angular - Angular 9中的空路由断言错误

ruby-on-rails - Rails 在暂存阶段自动加载 lib 类和模块,但在推送到生产环境时不会自动加载

ruby-on-rails - Mongoid has_many/belongs_to 有 'undefined method' 错误

ruby-on-rails - 制作一个新数组被认为是动态分配 Ruby

c# - ASP.NET MVC 5 中的路由可选参数

templates - 样式表不适用于使用 chi 路由器的 go html 模板

function - 如何使用 angularjs 路由调用 javascript 函数

AngularJS 和 Express 路由 404

ruby-on-rails - rails : Profile method execution count

ruby-on-rails - Rails 3 beta 3——是时候开始在新项目中使用它了吗?