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

Nothing happens and nothing appear #223

Open
whiteskull opened this issue Apr 1, 2024 · 1 comment
Open

Nothing happens and nothing appear #223

whiteskull opened this issue Apr 1, 2024 · 1 comment

Comments

@whiteskull
Copy link

whiteskull commented Apr 1, 2024

ruby 3.2.3
rails 7.1.3.2
rails-footnotes 7.1.0

rails_footnotes.rb

Footnotes.setup do |f|
f.enabled = Rails.env.development?
end if defined?(Footnotes) && Footnotes.respond_to?(:setup)

I start app in development mode, and nothing happens and nothing appears(

I tried add div in layout with id="footnotes_holder"

but it empty always(

There are no errors, but nothing happens.

@kichik
Copy link

kichik commented Nov 9, 2024

At least in my case that was because I am using Puma with threads. I'm not sure why, but this piece of code uses thread-local-storage members to enable footnotes:

thread_mattr_accessor :before_hooks
thread_mattr_accessor :after_hooks
thread_mattr_accessor :enabled, default: false

Changing thread_mattr_accessor to mattr_accessor fixed it for me.

I am far from a Ruby expert, but this monkey-patch in config/initializers/rails_footnotes.rb worked for me:

module Footnotes
  # the original implementation uses thread_mattr_accessor which doesn't work well with puma.
  # puma creates multiple threads and each of them has a different value for the same variable.
  # Footnotes.setup below only happens on the main thread and the value is NOT shared.
  # this code below is a workaround to make it work with puma.
  mattr_accessor :before_hooks, default: []
  mattr_accessor :after_hooks, default: []
  mattr_accessor :enabled, default: false
end

Footnotes.setup do |f|
  f.enabled = Rails.env.development?
end

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

No branches or pull requests

2 participants