Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set enabled to false in initializer (rails) #1038

Closed
patrykwojtynski opened this issue Jan 17, 2018 · 3 comments
Closed

Can't set enabled to false in initializer (rails) #1038

patrykwojtynski opened this issue Jan 17, 2018 · 3 comments

Comments

@patrykwojtynski
Copy link

I tried to have logging turned on only for specific endpoints in all environments. If you set enabled to false in the initializer it will not work.

In config/initializers/paper_trail.rb
PaperTrail.config.enabled = false

Then rails console

[1] pry(main)> PaperTrail.enabled?
=> true

After some digging, I found that engine overrides it to true when environment config is missing.

In PaperTrail::Rails::Engine

initializer "paper_trail.initialisation" do |app|
  PaperTrail.enabled = app.config.paper_trail.fetch(:enabled, true)
end

It probably should use PaperTrail.enabled? instead of true, or even not set enabled when config value is missing.

@jaredbeck
Copy link
Member

Hi Patryk.

If you set enabled to false in the initializer it will not work.

Per the docs, that should go in config/environments, not initializers. See https://github.com/airblade/paper_trail#2d-turning-papertrail-off

I tried to have logging turned on only for specific endpoints in all environments.

If that is your goal, try paper_trail_enabled_for_controller instead of PaperTrail.enabled. See https://github.com/airblade/paper_trail#per-request

@jaredbeck
Copy link
Member

Hi Patryk, I hope my comments helped. I haven't heard back so I'm going to close this, but please let me know if you find behavior that doesn't match the documentation.

@oehlschl
Copy link

oehlschl commented Jan 2, 2019

Thankful to find this thread after debugging the same "issue". It's worth noting that some documentation does include the config.enabled option in an initializer; see https://github.com/paper-trail-gem/paper_trail#1e1-global

# config/initializers/paper_trail.rb
PaperTrail.config.enabled = true

[...]
These options are intended to be set only once, during app initialization (eg. in config/initializers).

I'll open a PR that clarifies the readme for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants