rollbar-gem icon indicating copy to clipboard operation
rollbar-gem copied to clipboard

There is any way to disable js wrapper at controller level?

Open ngelx opened this issue 6 years ago • 5 comments

Hi, I need to disable the js inclusion for some specific actions. There is any way I could achieve this?

Thanks

ngelx avatar Feb 13 '19 04:02 ngelx

@waltjones could you take a look at this?

jessewgibbs avatar Feb 13 '19 17:02 jessewgibbs

@ngelx, There is an env key rollbar-gem uses internally to ensure the JS is never injected twice to the same response. You can put this in your controller before render, and it will skip injecting the JS for that request.

request.env['rollbar.js_is_injected'] = true

However, I should not be recommending this. It's undocumented and should be treated as subject to change. Still, it's there and that's how it works.

Maybe it would make sense to add a documented, reliable flag. I'll reply here with any update on that.

waltjones avatar Feb 13 '19 21:02 waltjones

@waltjones thanks! adding a documented interface for disabling this would be amazing. In the mean time, I've abstracted like:

class ApplicationController < ActionController::Base
...
  def do_not_injet_rollbar_js
    request.env['rollbar.js_is_injected'] = true
  end
...
end

And then, used in controller like:

before_action :do_not_injet_rollbar_js, only: :some_action

ngelx avatar Feb 14 '19 03:02 ngelx

Mark as enhancement, to add a documented request.env['rollbar.skip_js_injection'] or similarly named env flag.

waltjones avatar Feb 19 '19 21:02 waltjones

Thank you very much @waltjones and @ngelx!!

gregblass avatar Nov 25 '19 16:11 gregblass