首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >液体中的Rails javascript_include_tag标记

问液体中的Rails javascript_include_tag标记
EN

Stack Overflow用户
提问于 2014-09-06 16:38:29
回答 1查看 327关注 0票数 2

我正在尝试让javascript_include_tag("jquery")在rails内部的一个液体标签中工作。我的问题是javascript_include_tag("jquery")返回<script src="/javascript/jquery.js"></script>。而不是:<script src="/assets/jquery_ujs.js"></script>。此外,在生产中,标签不会添加文件指纹。

代码语言:javascript
复制
  class JqueryTag < ::Liquid::Tag
    # Include the stylesheet tag link helper
    include ActionView::Helpers::AssetTagHelper


    def render(context)
      return javascript_include_tag("jquery")
    end

  end

  Liquid::Template.register_tag('jquery_tag', JqueryTag)
EN

回答 1

Stack Overflow用户

发布于 2014-09-06 16:43:53

终于找到了答案。

仅包括include ActionView::Helpers::AssetTagHelper是不够的。

相反,我需要这样做。

代码语言:javascript
复制
  class JqueryTag < ::Liquid::Tag

    def render(context)
      helpers.javascript_include_tag("jquery")
    end

    def helpers
      @helpers ||= ActionController::Base.helpers
    end

  end

  Liquid::Template.register_tag('jquery_tag', JqueryTag)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25698461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档