Rails rails 要如何在 controller 访问 asset 下的文件?

wcc526 · June 16, 2014 · Last by wcc526 replied at June 17, 2014 · 1337 hits

如果在 controller 中直接

使用 Rails.root.join('app','assets','images','1.jpg")

对于 Production 环境由于 fingerprint 会发生错误

controller 要如何像 view 一样使用 asset_path?谢谢!

#1 楼 @blacktulip 但是这样的话,使用也有问题,ActionController::Base.helpers.asset_path("文件名") 只会产生 '/assets/images/1-123213213.jpg' 这种相对路径 ,我需要的是绝对路径。

生产环境下,assets 在 public 下,但是开发环境下 assets 在 apps 下,要怎样获取当前环境下 assets 的绝对路径呢?谢谢!

You need to Sign in before reply, if you don't have an account, please Sign up first.