xray-rails icon indicating copy to clipboard operation
xray-rails copied to clipboard

xray-rails 0.3.2 and sprockets 4

Open rocket-turtle opened this issue 4 years ago • 0 comments

We had some trouble to upgrade to sprockets 4 so I want to share our solution.

Include this MP in your application.rb (xray-rails must allready be required)

      config.after_initialize do
        if Gem::Version.new(Xray::VERSION) > Gem::Version.new('0.3.2')
          raise('This monkey patch is no longer necessary.')
        end

        Xray::Engine::JavascriptPreprocessor.class_eval do
          # See also https://github.com/brentd/xray-rails/issues/88
          # This is fixed in https://github.com/brentd/xray-rails/pull/103
          def self.run(filename, source, context)
            path = Pathname.new(context.filename).to_s
            if path =~ /^#{Rails.root}.+\.(jst)(\.|$)/
              Xray.augment_template(source, path)
            else
              source
            end
          end
        end
      end

This will no longer be necessary with the next release of xray-rails. You could include

Add = javascript_include_tag 'xray', nonce: true if Rails.env.development? as last element of the head tag. You need to make sure jQuery is already available.

Add = render partial: '/xray_bar' if Rails.env.development? as first element of the body tag. This will no longer be necessary if this MR is merged https://github.com/brentd/xray-rails/pull/101

Please let me know if you made some different changes.

rocket-turtle avatar Oct 15 '21 05:10 rocket-turtle