Rails 3旧版“资产"路线 [英] Rails 3 legacy "assets" routes

查看:92
本文介绍了Rails 3旧版“资产"路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Rails 2.3.14应用程序升级到Rails 3.2.1的过程中 到目前为止,唯一的问题是无法指定到我们的旧资产资源的路由.

I'm in the process of upgrading from a Rails 2.3.14 app to Rails 3.2.1 So far, the only issue is an inability to specify routes to our legacy assets resources.

config/application.rb 中:

config.assets.enabled = false

以下工作原理(路径不正确):

The following works (with an incorrect path):

resources :company_assets, :controller => 'assets', :as => :assets

但是,当然,路径是'/company_assets/*'.

当我尝试建立路径以使其为'/assets/*'时,路由将无法生成. 无法生成" ,是指运行:

As soon as I try to make the path so it's '/assets/*', the routes fail to generate. By "fail to generate", I mean running:

rake routes | grep assets

什么也没给我显示.

这是无法正确生成路由的示例:

Here's an example of routes that fail to correctly generate:

resources :company_assets, :controller => 'assets', :as => :assets, :path => 'assets'

# or

resources :assets

当我在Rails控制台中四处查看时,似乎存在与资产相关的路线,但它们似乎等同于指定了以下路线:

When I poke around in the Rails console, it appears there are asset related routes, but they seem to be equivalent to having specified:

resource :assets

代替:

resources :assets

(注意单数还是复数)

是否可以在不维护现有路径的情况下保持向后兼容性?

Is it possible to maintain backward compatibility here without mangling existing paths?

推荐答案

是的,有可能.

发生这种情况的原因是因为(处理资产管道的)链轮接管了/assets路线.

The reason this happens is because Sprockets (which handles the asset pipeline) takes over the /assets route.

您可以通过将Sprockets添加到您的application.rb中来更改路线:

You can change the route that Sprockets uses by adding this to your application.rb:

config.assets.prefix     = "/x"

其中x是新路线.

我在一个生产应用程序中执行此操作,因为回形针将其文件存储在/assets中.

I do this in one of my production apps because paperclip was storing its files in /assets.

一个升级提示:与 查看全文

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