【问题标题】:Rails console - use image_tag methodRails 控制台 - 使用 image_tag 方法
【发布时间】:2011-05-05 07:05:46
【问题描述】:

如何在 Rails 控制台中执行 image_tag 方法

  1. 运行控制台 $ 导轨 c

  2. 加载助手

    包括 ActionView::Helpers

  3. 执行命令

    image_tag('test.png')

我遇到了一个奇怪的错误。

请帮忙!

【问题讨论】:

    标签: ruby-on-rails helper irb actionview actionviewhelper


    【解决方案1】:

    不确定您为什么会收到该错误。很奇怪。

    但是 Rails 控制台通过 helper 变量公开了 helper 方法。所以这应该有效:

    helper.image_tag('test.png')
    

    【讨论】:

      【解决方案2】:

      好的...我找到了解决方案。该错误仅在 Rails 3 中显示,但我通过设置

        config.action_controller.asset_host = "http://..."
        config.action_mailer.asset_host = "http://..."
      

      在我的环境文件中(例如 development.rb)。 难以置信!

      此功能现在是插件https://github.com/xpepermint/js_erb 的一部分。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-27
        • 1970-01-01
        • 2014-03-02
        • 1970-01-01
        • 1970-01-01
        • 2013-05-02
        • 2011-05-11
        相关资源
        最近更新 更多