ActionController::Base.relative_url_root 的替代品是什么? [英] What is the replacement for ActionController::Base.relative_url_root?

查看:17
本文介绍了ActionController::Base.relative_url_root 的替代品是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 2.x rails 应用程序移植到 rails3;我们将其称为 foo-app.Foo-app 是更大的 rails 应用程序的一部分,位于 main_rails_app.com/foo-app.以前我们只是在我们的 foo-app 生产配置中设置以下内容,以确保我们的 foo-app 路由正常工作:

I am porting a 2.x rails app to rails3; we'll call it foo-app. Foo-app is one section of a larger rails app and lives at main_rails_app.com/foo-app. Previously we just set up the following in our foo-app production config to ensure that our foo-app routes worked properly:

ActionController::Base.relative_url_root = "/foo-app"

但是,使用 rails3,我现在得到:

However, with rails3, I now get:

DEPRECATION WARNING: ActionController::Base.relative_url_root is ineffective. Please stop using it.

我已经将配置条目更改为以下内容:

I have since changed the config entry to the following:

config.action_controller.relative_url_root = "/foo-app"

这主要是因为所有对外部资源 (javascript/css/images) 的调用都将使用/foo-app.但是,我的路由都没有适当改变,或者换句话说,foo-app root_path 在我期望的时候给了我 '/'.

This mostly works in that all calls to external resources (javascript/css/images) will use /foo-app. However, none of my routes change appropriately, or put another way, foo-app root_path gives me '/' when I would expect '/foo-app'.

两个问题:

  1. ActionController::Base.relative_url_root 的替代品是什么
  2. 如果是 config.action_controller.relative_url_root,那么为什么我的路由没有反映我设置的 relative_url_root 值?

推荐答案

您应该能够处理 routes.rb 文件中的所有内容.将您当前的所有路线包装在范围内;例如.

You should be able to handle all that within the routes.rb file. Wrap all your current routes in scope; for instance.

scope "/context_root" do
   resources :controller
   resources :another_controller
   match 'welcome/', :to => "welcome#index"
   root :to => "welcome#index"
end

然后您可以通过 rake routes 验证您的路由,它们应该相应地显示您的路由,包括您的上下文根(relative_url_root)

You can then verify your routing via the rake routes they should show your routes accordingly, including your context root(relative_url_root)

这篇关于ActionController::Base.relative_url_root 的替代品是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆