Skip to content
Provides an easy way to create Rack Middleware that injects things into the response body
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Allows you to create simple Rack Middleware that will insert HTML (or whatever!) into responses at specific points.

This gem was extracted from Rack::Insight.

Project Rack::Toolbar
gem name rack-toolbar
license MIT
expert support Get help on Codementor
download rank Total Downloads
version Gem Version
dependencies Dependency Status
code quality Code Climate
inline documenation Inline docs
continuous integration Build Status
test coverage Coverage Status
homepage on
documentation on
live chat Join the chat at
Spread ♡ⓛⓞⓥⓔ♡ on Coderbits, on Coderwall

NOTE: As it goes with all middleware that modifies the response, not compatible with Rails' streaming responses because it modifies the response.


Add this line to your application's Gemfile:

gem 'rack-toolbar'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-toolbar


If your app is delivering a response like:


Simple Setup

You want to inject something into the response!

Configure your app to use Rack::Toolbar

use Rack::Toolbar, {snippet: "<div>More Important!</div>", insertion_point: "<body>", insertion_method: :after}

The div specified will be injected :after the <body tag.

    <div>More Important!</div>

Easy Setup

You want to build a Middleware that will deliver a custom response based on whatever.

Create your middleware to inherit from Rack::Toolbar, and define a render method:

class CustomMiddleware < Rack::Toolbar
  def render

Configure your app to use your CustomMiddleware. You can still use the :insertion_* options, but :snippet will be ignored.

use CustomMiddleware, {insertion_point: "</head>", insertion_method: :before}


After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to


  1. Fork it ([my-github-username]/destination_errors/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Make sure to add tests!
  6. Create a new Pull Request


See the Network View


Other projects which will allow you to build Middleware to inject stuff into responses:

You can’t perform that action at this time.