简体   繁体   English

Rails中的资产访问路径

[英]Assets access path in rails

In development/test mode I add following in config/environments/*.rb: 在开发/测试模式下,我在config / environments / *。rb中添加以下内容:

config.assets.paths << "whatever_path"

When I start webrick, image at "whatever_path/collections/image.jpg" is accessible through this path: 当我启动webrick时,可通过以下路径访问“ whatever_path / collections / image.jpg”中的图像:

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

How (without fs manipulation) can I make it accessible through this path: 如何(无需fs操纵)如何通过以下路径访问它:

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

I need this redirect to work only in test mode. 我需要此重定向才能仅在测试模式下工作。

As an alternative solution to my problem, i added following in features/support/asset_host.rb 作为解决我的问题的替代方法,我在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]))
}

this suppresses the error only if file exists in dummy fs at whatever_path 仅当文件在what_path的虚拟fs中存在时,这才抑制错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM