• Stars
    star
    1,524
  • Rank 30,745 (Top 0.7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 16 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Every Rails page has footnotes that gives information about your application and links back to your editor

Rails 7 Footnotes

Rails footnotes 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.

Installation

  1. Add to your Gemfile with bundle add rails-footnotes
  2. Run bundle install
  3. Generate the initializer with bin/rails generate rails_footnotes:install

This will create an initializer with default config and some examples.

Hooks

You can run blocks before and after footnotes are evaluated.

Footnotes.setup do |config|
  config.before do |controller, filter|
    filter.notes = (controller.class.name =~ /Message/ && controller.action_name == 'index' ? [:assigns] : [])
  end

  config.before do |controller, filter|
    filter.notes |= [:params] if controller.class.name =~ /Profile/ && controller.action_name == 'edit'
  end
end

Editor links

By default, files are linked to open in TextMate, but you can use any editor with a URL scheme. Here are some examples for other editors:

MacVim

In config/initializers/rails-footnotes.rb do:

f.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'

Here you need 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 number.

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 3

Install subl, then use:

f.prefix = 'subl://open?url=file://%s&line=%d&column=%d'

Use with Docker, Vagrant, or other virtual machines

If you're running your app in a container or VM, you'll find that the edit links won't work because the paths point to the VM directory and not your native directory. To solve this, you can use a lambda for the prefix and modify the pathname accordingly.

For example,

f.prefix = ->(*args) do
  filename = args[0].sub '/docker', '/Users/name/projects/myproject'
  "subl://open?url=file://#{filename}&line=#{args[1]}&column=#{args[2]}"
end

replaces the VM directory /docker with the macOS directory containing the source code.

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:

f.no_style = true

You can also lock the footnotes to the top of the window, hidden by default, and accessible via a small button fixed to the top-right of your browser:

f.lock_top_right = true

To set the font-size for the footnotes:

f.font_size = '13px'

Another option is to allow multiple notes to be opened at the same time:

f.multiple_notes = true

Finally, you can control which notes you want to show. The default are:

f.notes = [:session, :cookies, :params, :filters, :routes, :env, :queries, :log]

Setting f.notes = [] will show none of the available notes, although the supporting CSS and JavaScript will still be included. To completely disable all rails-footnotes content on a page, include params[:footnotes] = 'false' in the request.

Creating your own notes

Creating your notes to integrate with Footnotes is easy.

  1. Create a Footnotes::Notes::YourExampleNote class
  2. Implement the necessary methods (check abstract_note.rb[link:lib/rails-footnotes/abstract_note.rb] file in lib/rails-footnotes)
  3. Append your example note in Footnotes::Filter.notes array (usually at the end of your environment file or in the 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, add in your initializer:

f.notes += [:current_user]

Footnote position

By default the notes will be showed at the bottom of your page (appended just before </body>). If you'd like the footnote, to be at 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

Bugs and Feedback

If you discover any bugs, please open an issue. If you just want to give some positive feedback or drop a line, that's fine too!

More Repositories

1

rails3-generators

Rails 3 compatible generators for gems that don't have them yet
Ruby
326
star
2

middleman-heroku-static-app

Precompile your static Middleman site when you push to Heroku
Ruby
124
star
3

jekyll-postfiles

files for your jekyll posts
Ruby
42
star
4

brewbygems

Make RubyGems and Homebrew play nice together
Ruby
42
star
5

xcode-git-build-scripts

making git and xcode together less painful since 2008
Shell
29
star
6

unpwn

Ruby
26
star
7

gerrit-tools

Tools to make working with Gerrit code review easier
24
star
8

growlnotify

I am lazy and don't want to download a DMG to install growlnotify
Shell
20
star
9

handbrake-cli-batch

Runs HandBrakeCLI on entire folders at once, yay
Ruby
18
star
10

feedyour.email

Ruby
17
star
11

dotfiles

Shell
13
star
12

cuberule.com

the cube rule of food identification, explained
HTML
13
star
13

dash-rust

Ruby
12
star
14

tm

mate wrapper, like hub for git
Shell
9
star
15

daneel

A 19,230 year old robot.
Ruby
8
star
16

simple_presenter

presenter layer for rails
Ruby
7
star
17

sparks

a tiny campfire library
Ruby
5
star
18

indirect

Ruby
5
star
19

actually.men

CSS
4
star
20

emojinate

convert unicode emojis into :names: and pngs
Ruby
3
star
21

dash-emoji

Ruby
3
star
22

arko.net

homepage
HTML
3
star
23

ey-jenkins

Jenkins, on EY, instantly deployable with `ey deploy`
Ruby
3
star
24

lita-tweet

Ruby
3
star
25

devise-unpwn

ensure user passwords haven't been pwned
Ruby
3
star
26

puppet-prefpane

Use puppet to install prefpanes
Ruby
3
star
27

dash-httpstatuses

Ruby
2
star
28

fast-rails

Ruby
2
star
29

dm-activemodel

An adapter to help DataMapper conform to the ActiveModel API without warnings
Ruby
2
star
30

indirect.github.com

2
star
31

andre.arko.net

blog
JavaScript
2
star
32

dash-phantomjs

Ruby
2
star
33

ecosystem_metrics

Perl
2
star
34

next_id

Ruby
2
star
35

trackparser

Music.app Track Parser
AppleScript
1
star
36

idonethis-report

Ruby
1
star
37

puppet-ponysay

ponysay and horsefortun.es, automatically
Ruby
1
star
38

twumblr

Ruby
1
star
39

homebrew-tap

Personal Homebrew formulas
Ruby
1
star
40

igooglefight

iPhone webapp for google fights
JavaScript
1
star
41

Apple-Watch-Poketch

Swift
1
star
42

rbdramas.com

The dramas.
1
star
43

devise-passkey

Ruby
1
star
44

rake-rustpkg

Ruby
1
star
45

indirect.io

projects homepage
Ruby
1
star
46

isitapipelineproblem.com

well, is it?
CSS
1
star
47

startupconsultants.us

HTML
1
star
48

znc

IRC bouncer (fork with procfile)
C++
1
star
49

dowomentalkmore.com

CSS
1
star