【问题标题】:Rails - How would I get the URL of a single image asset in the controller?Rails - 如何在控制器中获取单个图像资产的 URL?
【发布时间】:2011-05-24 21:56:30
【问题描述】:

我尝试包含ActionView::Helpers::AssetTagHelper,然后使用image_path() 方法,但它让我很伤心:

undefined local variable or method `config' for ActionView::Helpers::AssetTagHelper:Module

我可能缺少一些简单的东西。有什么想法吗?

【问题讨论】:

  • 请说明您在哪里包含模块。
  • 哦,对不起-我正在尝试在控制器中执行此操作。

标签: ruby-on-rails-3 url controller actionview actionviewhelper


【解决方案1】:

我在 Barlow 的回答中找到了解决方案:How can I use image_path inside Rails 3 Controller

view_context.image_path('/path/to/image')

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 1970-01-01
    • 2011-09-25
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多