views:

22

answers:

3

Hi guys,

Does anybody know how to debug in rails in the Model? I have a method that is now working and I was trying to check the variable's value in between typing logger.debug val_name that's working in the controllers but not in the models does anyone know why? The model is not inherited from Active Record if it can be the problem. Is there any way to debug it?

+1  A: 

You can just do "puts" inside of your model method calls and it'll output. You can see it in the rails logs, or the console's output.

Jesse Wolgamott
this was very helpful and easy, I wonder why I didn't try that :)
Dennis
A: 

since your model is not an ActiveRecord it does not have the logger method mixed-in

you can add it like this (probably other better ways to do it as well)

class YourModelThatIsNotActiveRecord
    def logger
        RAILS_DEFAULT_LOGGER
    end
end

a bunch of great information here as well - http://guides.rubyonrails.org/debugging_rails_applications.html

house9
A: 

If you are spinning up Mongrel using script/server in development, this might work:

  1. installe the ruby-debug gem, if you don't have it already: gem install ruby-debug;
  2. add require 'ruby-debug' to config/environments/development.rb;
  3. put the line debugger in the source where you want to initiate a debugging session.

Look at this official guide for more information: http://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-ruby-debug

ihoka