rails 4的asset_path帮手是否使用asset.prefix?

我configuration我的rails应用程序使用不同的资产前缀,通过编辑文件conf/application.rb

+config.assets.prefix = '/wrapper/thing'

它适用于资产pipe道,但是当我尝试在我的视图中使用它时。

<%= asset_path('milk.png') %>

它仍然输出"/assets/milk.png"而不是"/wrapper/thing/milk.png"

我错过了什么吗?

你应该仔细检查你的文件名,因为有一个类似的错误报告,结果是一个错字。

基本上在Rails 4中会发生什么,如果资产不存在,则前缀被省略。

您可以在Rails控制台中testing他们在线程中的行为: https : //github.com/rails/rails/issues/15873

 $ rails new path-test $ touch app/assets/images/hello.png $ rails c Loading development environment (Rails 4.1.1) >> Rails.application.config.assets.prefix => "/assets" >> ActionController::Base.helpers.asset_path "hello.png" => "/assets/hello.png" >> ActionController::Base.helpers.asset_path "foo.png" => "/foo.png" 

仅供参考,你可能会得到一个更快的答复Rails的问题在Stackoverflow那里有更大的Rails社区: https : //stackoverflow.com/questions/tagged/ruby-on-rails

希望这可以帮助