This plugin works with Rails 3. Please follow the instruction mentioned here . If you have any problem then please create an issue . Also note that all the Rails 3 work is happening in a branch called rails3_gem if you want to look at source code. The master branch is for Rails 2.x work.
I love hoptoad. I especially like the ability to catch exceptions in rake tasks and have those exceptions logged at hoptoad using hoptoad_notifier.
Currently I am working on a government project where hoptoad can’t be used. Rather than writing code that captures all the information about exception, I am letting hoptoad_notifier do all the heavy lifting.
Instead of sending the information to hoptoad this plugin ensures that information is written to a database.
This plugin has been tested with Rails 2.3.5 .
Open config/environment.rb and add following line.
config.gem 'hoptoad_notifier'
Install hoptoad_notifier gem by executing
sudo rake gems:install
vendor gem by executing rake gems:unpack GEM=hoptoad_notifier .
Install exception2db plugin
ruby script/plugin install git://github.com/neerajdotname/exception2db.git
Create an empty exception2db.rb file
touch config/initializers/exception2db.rb
Add following text to config/initializers/exception2db.rb file
HoptoadNotifier.configure do |config| end module HoptoadNotifier def self.send_notice(data) Exception2db.create(:exception => data.to_xml) end end
Generate migration
ruby script/generate migration add_exception2db_table
Open the migration file and add following text
class AddException2dbTable < ActiveRecord::Migration def self.up create_table :exception2dbs do |t| t.text :exception, :null => false t.datetime :created_at, :null => false end end def self.down drop_table :exception2dbs end end
Run migration
rake db:migrate
Whenever there is an exception that exception will be logged to database. Remember all the hoptoad rules apply. It means no excpetion will be logged in development environment.
To view exceptions visit http://localhost:3000/exception2db .
In order to test this feature first add following line in application_controller.rb .
def local_request? false end
Then start the server in non development environment. Once again please start your server in production
or some other environment. Exceptions in development mode are ignored by hoptoad.
Go to a url that raises exception.
Then visit http://localhost:3000/exception2db . If you are not seeing not authorized message then read the next section.
If you are not seeing the logging of exception then please read this article .
By default no security check is performed while visiting http://localhost:3000/exception2db in development mode. In other environment a security check is done. At the bottom of config/initializers/exception2db.rb add something like this to configure security settings.
Exception2dbConfig.set = { :is_allowed_to_view => lambda {|controller| controller.send('admin_logged_in?') } }
Above code assumes that you have admin_logged_in? method defined in application_controller.rb . The is_allowed_to_view key accepts a proc and controller is provided to you. So you can call any controller method.
Stand in the current directory and run following command. I assume that you have rspec already installed.
spec spec
Stand in the current directory and run following command. I assume you have cucumber already installed.
cucumber
Copyright © 2010 neerajdotname, released under the MIT license