Can I print debug messages to the browser console in Ruby on Rails?

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!!"