2014-09-06 78 views
1

我想要javascript_include_tag("jquery")在軌道內的液體標籤工作。我的問題是,javascript_include_tag("jquery")返回<script src="/javascript/jquery.js"></script>。而不是:<script src="/assets/jquery_ujs.js"></script>。同樣在生產中,標籤不會添加文件指紋。Rails JavaScript_include_tag標籤在液體

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) 

回答

1

Finaly找到了答案。

包括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)