Ruby on Rails Error Tracking installation
Install with the wizard
Run this command in your project directory to add PostHog to your Rails project. The wizard detects your framework, installs the SDK, and sets up your first events.
Or set it up manually by following the rest of this guide.
- 1
Install the gems
RequiredAdd the
posthog-rubyandposthog-railsgems to your Gemfile:GemfileThen run:
Terminal - 2
Generate the initializer
RequiredRun the install generator to create the PostHog initializer:
TerminalThis will create
config/initializers/posthog.rbwith sensible defaults and documentation. - 3
Configure PostHog
RequiredUpdate
config/initializers/posthog.rbwith your project token and host:config/initializers/posthog.rb - 4
Send events
RecommendedOnce installed, you can manually send events to test your integration:
Ruby - 5
Configure error tracking
RequiredUpdate
config/initializers/posthog.rbto enable automatic exception capture:config/initializers/posthog.rb - 6
Automatic exception capture
RecommendedWith
auto_capture_exceptionsenabled, exceptions are automatically captured from your controllers:app/controllers/posts_controller.rb - 7
Background jobs
OptionalWhen
auto_instrument_active_jobis enabled, ActiveJob exceptions are automatically captured:app/jobs/email_job.rb - 8
Manually capture exceptions
OptionalYou can also manually capture exceptions that you handle in your application:
Ruby - 9







