richpeck / exception_handler

Ruby on Rails Custom Error Pages
509 stars 70 forks source link

Mongoid support #32

Open Startouf opened 8 years ago

Startouf commented 8 years ago

I see no mention of Mongoid anywhere. Is it possible to work with Mongoid at all ? (Even if the database logging doesn't work yet ?)

EDIT -

The current version will cause a wonderful exception (haha sorry about that) when started with a Mongoid-backed DB with default configuration. Adding...

config.exception_handler = {
    db: false
  }

...doesn't seem to help.

Here's the top of my stack trace

[Rails root]/app/models/exception_handler/error.rb:2:in `<module:ExceptionHandler>': uninitialized constant ExceptionHandler::ActiveRecord (NameError)
        from [Rails root]/app/models/exception_handler/error.rb:1:in `<top (required)>'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/concurrency/share_lock.rb:117:in `exclusive'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies/interlock.rb:11:in `loading'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:475:in `each'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:475:in `block in eager_load!'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:473:in `each'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:473:in `eager_load!'
        from [Rails root]/config.ru:6:in `block in <main>'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `instance_eval'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `initialize'
        from [Rails root]/config.ru:in `new'
        from [Rails root]/config.ru:in `<main>'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `eval'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `new_from_string'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:40:in `parse_file'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/server.rb:318:in `build_app_and_options_from_config'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/server.rb:218:in `app'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/commands/server.rb:58:in `app'
Startouf commented 8 years ago

Sorry, I didn't even notice I ran this after generating the files for my app. Removing the ActiveRecord inheritance and adding include Mongoid::Document in the generated model fixed it, and it is probably gonna work with Mongoid.

So the only point that needs to be revisited, is not to generate ActiveRecord model when running the generator script on Mongoid backed Rails.

richpeck commented 7 years ago

Hey thank you for the PR - let me check through it will be a few minutes

fatihtas commented 4 years ago

0.8.0.0 doesn't work with mongoid, I am triying almost half day, I added include Mongoid::Document include Mongoid::Timestamps

and tried to implement @Startouf s commits on my model file as well.. can you please check it @richpeck