Can I Print Debug Messages To The Browser Console In Ruby On Rails?


Answer :

Simple. Just call puts 'your debug message' and it will be printed to where the server is logging. For instance, if you are running the rails server only by running rails s on a terminal, the output of puts will be on this same terminal. If you need more 'power' to debug, you should consider using IDE's like RubyMine to debug your code. Thus, you can place breakpoints and see all the application state.


You can use console.log() in your views:

#view.html.erb <script>     console.log("Message"); </script> 

If you want to log in your Model, try:

Rails.logger.debug "message!!" 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?