Rails - 如何获取控制器中单个图像资源的URL?

dig*_*tie 3 url controller actionview actionviewhelper ruby-on-rails-3

我试过包括ActionView::Helpers::AssetTagHelper然后使用这个image_path()方法然而它让我感到悲伤:

undefined local variable or method `config' for ActionView::Helpers::AssetTagHelper:Module
Run Code Online (Sandbox Code Playgroud)

我可能还有一些简单的东西.有任何想法吗?

小智 10

我在Barlow的答案中找到了解决方案:如何在Rails 3 Controller中使用image_path

view_context.image_path('/path/to/image')
Run Code Online (Sandbox Code Playgroud)

似乎对我有用,不需要在Controller中包含帮助器