资产轨道中的资产访问路径

时间:2013-10-17 10:20:12

标签: ruby-on-rails redirect capybara assets

在开发/测试模式下,我在config / environments / * .rb:

中添加以下内容
config.assets.paths << "whatever_path"

当我开始webrick时,可以通过以下路径访问“whatever_path / collections / image.jpg”中的图像:

http://0.0.0.0:3000/assets/collections/image.jpg

如何(没有fs操作)我可以通过这条路径访问它:

http://0.0.0.0:3000/collections/image.jpg 

我需要此重定向才能在测试模式下工作。

1 个答案:

答案 0 :(得分:0)

作为我的问题的替代解决方案,我在features / support / asset_host.rb

中添加了以下内容
ActionController::Base.asset_host = Proc.new { |source|
  true if source["/collections"] and File.exists?(Rails.root.join("whatever_path",source[1..-1]))
}

仅当文件存在于whatever_path

中的虚拟fs中时,才会抑制错误