<img src=“https://travis-ci.org/josevalim/rails-footnotes.png” />
If you are developing in Rails you should know the plugin! It displays footnotes in your application for easy debugging, such as sessions, request parameters, cookies, filter chain, routes, queries, etc.
Even more, it contains links to open files directly in your editor including your backtrace lines.
NOTE: Since this branch aims Rails 3 support, if you want to use it with Rails 2.3 you should check this branch:
https://github.com/josevalim/rails-footnotes/tree/rails2
Install Rails Footnotes is very easy.
gem 'rails-footnotes', '>= 3.7.9', :group => :development
After you install RailsFootnotes and add it to your Gemfile, you need to run the generator:
rails generate rails_footnotes:install
In RAILS_ROOT/config/environments/development.rb (yes, you want it only in development):
gem "rails-footnotes", '< 3.7.0', :group => :development
For version greater than 3.7.0
If you want to add alternate logic to enable or disable footnotes, add something like this to config/initializers/footnotes.rb:
if defined?(Footnotes) && Rails.env.development? Footnotes.run! # first of all # ... other init code end
If you want to add alternate logic to config footnotes without commit it to SCM, add your code to .footnotes:
Footnotes::Filter.notes = []
this code temporarily disables notes for all controllers
Footnotes.setup do |config| config.before {|controller, filter| filter.notes = controller.class.name =~ /Message/ && \ controller.action_name == 'index' ? [:assigns] : []} config.before {|controller, filter| filter.notes |= [:params] if controller.class.name =~ /Profile/ && \ controller.action_name == 'edit' } end
If you are not using Textmate as text editor, MacVim and Sublime Text 2 are also compatible.
MacVim
In your environment.rb or in an initializer do:
Footnotes::Filter.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'
Where you are going to choose a prefix compatible with your text editor. The %s is replaced by the name of the file, the first %d is replaced by the line number and the second %d is replaced by the column.
Take note that the order in which the file name (%s), line number (%d) and column number (%d) appears is important. We assume that they appear in that order. “foo://line=%d&file=%s” (%d precedes %s) would throw out an error.
Sublime Text 2
-
Keep the Textmate prefix,
Footnotes::Filter.prefix = 'txmt://open?url=file://%s&line=%d&column=%d'
-
Install subl-handler
-
Open subl-handler. Go to preferences (SublHandler > Preferences), and point “Path to subl” to your installed instance. (EG, /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl). Note: do not escape the whitespaces, subl-handler accounts for those.
-
Install RCDefault. It’s OSX 10.2, but it works.
-
Go to RCDefaultApp (OS System Preferences > DefaultApps). Go to URL section, select “tmxt” extension, and set default applicaiton to “SublHandler”.
Footnotes Display Options
By default, footnotes are appended at the end of the page with default stylesheet. If you want to change their position, you can define a div with id “footnotes_holder” or define your own stylesheet by turning footnotes stylesheet off:
Footnotes::Filter.no_style = true
Another option is to allow multiple notes to be opened at the same time:
Footnotes::Filter.multiple_notes = true
Finally, you can control which notes you want to show. The default are:
Footnotes::Filter.notes = [:session, :cookies, :params, :filters, :routes, :env, :queries, :log, :general]
Create your notes to integrate with Footnotes is easy.
-
Create a Footnotes::Notes::YourExampleNote class
-
Implement the necessary methods (check abstract_note.rb file in lib/notes)
-
Append your example note in Footnotes::Filter.notes array (usually at the end of your environment file or in an initializer):
For example, to create a note that shows info about the user logged in your application you just have to do:
module Footnotes module Notes class CurrentUserNote < AbstractNote # This method always receives a controller # def initialize(controller) @current_user = controller.instance_variable_get("@current_user") end # Returns the title that represents this note. # def title "Current user: #{@current_user.name}" end # This Note is only valid if we actually found an user # If it's not valid, it won't be displayed # def valid? @current_user end # The fieldset content # def content escape(@current_user.inspect) end end end end
Then put in your environment:
Footnotes::Filter.notes += [:current_user]
By default the notes will be showed at the bottom of your page (appended just before </body>). If you’d like these notes on a different place (perhaps for aesthetical reasons) you can edit one of your views and add:
<div id="footnotes_holder"></div>
at an appropriate place, your notes will now appear inside div#footnotes_holder
-
Leon Li - github.com/scorpio
-
Keenan Brock - github.com/kbrock
-
Ivan Storck - github.com/ivanoats
-
Kris Chamber - github.com/kristopher
If you discover any bugs, please send an e-mail to [email protected] If you just want to give some positive feedback or drop a line, that’s fine too!
This plugin was maintained until version 3.6 by José Valim
Copyright © 2009 José Valim ([email protected]) blog.plataformatec.com.br
This plugin was created and maintained until version 2.0 by Duane Johnson:
Copyright © 2006 InquiryLabs, Inc. blog.inquirylabs.com