我正在尝试让javascript_include_tag("jquery")在rails内部的一个液体标签中工作。我的问题是javascript_include_tag("jquery")返回<script src="/javascript/jquery.js"></script>。而不是:<script src="/assets/jquery_ujs.js"></script>。此外,在生产中,标签不会添加文件指纹。
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)发布于 2014-09-06 16:43:53
终于找到了答案。
仅包括include ActionView::Helpers::AssetTagHelper是不够的。
相反,我需要这样做。
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)https://stackoverflow.com/questions/25698461
复制相似问题