{ "html": "
\n

Ruby on Rails

\n

In Rails, all uncaught exceptions will be automatically reported.

\n

We support Rails 3 and newer.

\n
\n

Installation

\n

Install the SDK via Rubygems by adding it to your Gemfile:

\n
gem "sentry-raven"\n
\n
\n
\n
\n

Configuration

\n

Open up config/application.rb and configure the DSN, and any other settings\nyou need:

\n
Raven.configure do |config|\n  config.dsn = '___DSN___'\nend\n
\n
\n

If you have added items to Rails’ log filtering,\nyou can also make sure that those items are not sent to Sentry:

\n
# in your application.rb:\nconfig.filter_parameters << :password\n\n# in an initializer, like sentry.rb\nRaven.configure do |config|\n  config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)\nend\n
\n
\n
\n
\n

Params and sessions

\n
class ApplicationController < ActionController::Base\n  before_action :set_raven_context\n\n  private\n\n  def set_raven_context\n    Raven.user_context(id: session[:current_user_id]) # or anything else in session\n    Raven.extra_context(params: params.to_unsafe_h, url: request.url)\n  end\nend\n
\n
\n
\n
\n

Authlogic

\n

When using Authlogic for authentication, you can provide user context by\nbinding to session after_persisting and after_destroy events in\nuser_session.rb:

\n
class UserSession < Authlogic::Session::Base\n  # events binding\n  after_persisting :raven_set_user_context\n  after_destroy :raven_clear_user_context\n\n  def raven_set_user_context\n    Raven.user_context({\n      'id' => self.user.id,\n      'email' => self.user.email,\n      'username' => self.user.username\n    })\n  end\n\n  def raven_clear_user_context\n    Raven.user_context({})\n  end\nend\n
\n
\n
\n
\n", "link": "https://docs.getsentry.com/clients/ruby/integrations/rails/", "id": "ruby-rails", "name": "Rails" }