Ole Brum
Ole Brum

Reputation: 51

How do I debug a rails 3 gem?

I have created a gem/engine based on this tutorial:

http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/

However, I am getting an error when trying to use the gem in a newly created application. I am getting a "Routing Error - undefined method `sub' for nil:NilClass" when trying to access the application.

The only thing I can see in the log file is the same error. No stack trace/debug trace, so it is difficult to figure out where the error is coming from. Ideally I would like to get see the stack trace "from the gem", but it appears that rails does not debug errors originating from outside the application?

I'm using rvm, ruby 1.9.2, rails 3.0.1.

Here is my config/routes.rb file from the gem, although I do not think this is a routing error as the debug message suggests..

Rails.application.routes.draw do
    resources :pictures, :controller => 'morph/pictures'
end

Any suggestions?

Upvotes: 5

Views: 3076

Answers (2)

Christophe Belpaire
Christophe Belpaire

Reputation: 317

If you uncomment

Rails.backtrace_cleaner.remove_silencers!

in config/initializers/backtrace_silencers.rb it will display a more complete stacktrace. It worked for me.

Upvotes: 15

TK-421
TK-421

Reputation: 10763

Is there a backtrace in your console?

If you're unable to find any additional output, then you could put a 'debugger' statement somewhere near the start of your app and step through the source code until the error appears.

You can do the same with the gem/plugin source, too.

Edit: It appears the author has a link to demo code at the bottom of the article. That might also be useful.

Upvotes: 2

Related Questions