Pregunta

I'm using the rails-footnotes gem in my Rails 3.2 applications, but I can't seem to get the footnotes to register the existence of any partials: it always shows a zero partial count.

To be able to know how many and what partials are being displayed on a view easily like this is, I think, immensely useful, so I would really like to get this working (the rest works great), but I'm not sure what the problem is and am hoping someone else has had the same problem and was able to resolve it. Is there a setting I've potentially missed?

I don't think it's relevant, but I'm using OSX 10.6.8 and had some issues getting the gem to work with Sublime Text 2 properly, but they did get resolved (details in this StackOverflow answer).

Update:

It seems that the issue only exists for haml templates, as I am getting expected output for erb templates. It would seem that only erb templates are counted/recognized...?

Update 2:

@DonHopkins' answer below got all my Haml templates to register with Rails Footnotes. I put it in my config file as follows:

config/initializers/rails_footnotes.rb

if defined?(Footnotes) && Rails.env.development?
  Footnotes.run! # first of all
  Footnotes::Notes::LogNote::LoggingExtensions.module_eval do
    def add(*args, &block)
      super
      logged_message = args[2] + "\n"
      Footnotes::Notes::LogNote.log(logged_message)
      logged_message
    end
  end

  # ... other init code
  Footnotes::Filter.prefix = 'subl://open?url=file://%s&line=%d&column=%d'
end 
¿Fue útil?

Solución

I had a similar problem, although I am using erb templates, not haml. I fixed it with a monkey patch to rails-footnotes.

Looking at the rails-footnotes code (version 3.7.9), it looked to me like the problem is in this method:

module Footnotes
  module Notes
    class LogNote < AbstractNote
      ...
      module LoggingExtensions
        def add(*args, &block)
          logged_message = super
          Footnotes::Notes::LogNote.log(logged_message)
          logged_message
        end
      end
      ...
    end
  end
end

The add method is assuming that super returns the message that is being logged, but in my testing super was returning a boolean value. To solve the problem, I created a file called footnotes_patch.rb with the following:

Footnotes::Notes::LogNote::LoggingExtensions.module_eval do
  def add(*args, &block)
    super
    logged_message = args[2] + "\n"
    Footnotes::Notes::LogNote.log(logged_message)
    logged_message
  end
end

If you want to try the solution, put that file in config/initializers, then restart your application.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top