2

I'm trying to get javascript_include_tag("jquery") to work in a Liquid tag inside rails. My problem is that javascript_include_tag("jquery") returns <script src="/javascript/jquery.js"></script>. And not: <script src="/assets/jquery_ujs.js"></script>. Also in production the tag does not add the file fingerprint.

  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 Answer 1

2

Finaly found an answer.

Including include ActionView::Helpers::AssetTagHelper was not enough.

Instead i needed to do this.

  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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.