If I'm testing my Javascript code, I often use console.log to write messages to the browser console. I find it a convenient place to check for these messages.
Is it possible to output messages to the browser console from Ruby files within your Rails project? (E.g. from a method in the model)
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!!"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With