开发者

How to debug in Model?

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 va开发者_Python百科l_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?


Another way to log from anywhere in your application:

Rails.logger.debug "Show this message!"

This will always output to the log/development.log file.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜