 <p>Gems can configure their host apps by providing a <a href="http://api.rubyonrails.org/classes/Rails/Railtie.html">Railtie</a>.</p> <p>For example, here is a shortened version of how the <a href="https://github.com/charliesome/better_errors/blob/master/lib/better_errors/rails.rb">BetterErrors gem</a> does it:</p> <pre><code>module BetterErrors class Railtie &lt; Rails::Railtie initializer "better_errors.configure_rails_initialization" do Rails.application.middleware.use BetterErrors::Middleware end end end </code></pre>