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 a开发者_运维知识库pplication?
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?
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.
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.
精彩评论