0

is a very beginner question but even tho i cannot find any helpful documentation online.

I'm working on Discourse application which is Ruby on Rails + Ember based. I need to print out in my terminal (not in my view!) the value of a variable.

I try:

debugger

put varName

logger.debug varName

but none of them print anything in my console.

What i need to do is stop my console from running and print a value. Like debugger; would do in javascript. How can i do this simple task?

1) not sure if this change anything but the .rb file i try to debug is a "services".

2) yes, i read about pry, i installed it and add to my file: require 'pry' binding.pry But i don't see anything happening in the console.

Giorgia Sambrotta
  • 1,133
  • 1
  • 15
  • 45
  • 2
    Rails includes `byebug` by deafult, [check it out](https://github.com/deivid-rodriguez/byebug). – Gerry Apr 23 '17 at 11:50
  • And this should work in any part of the applicaton, correct? model, serializers, controllers, .. I put in my service and i don't get any debugging prompt. I now think i might not firing the right part of the application.. – Giorgia Sambrotta Apr 23 '17 at 12:43
  • @GiorgiaSambrotta If u are using just a rails console, you can simply add "puts var_name" – TiSer Apr 23 '17 at 13:46
  • 1
    @GiorgiaSambrotta and if you want to output within request - `binding.pry` will stop code execution for you and you should to take a look at terminal tab with your rails server. – TiSer Apr 23 '17 at 13:51
  • @TiSer thanks. Is rails console different console from terminal? If yes, where i can see it? `binding.pry` unfortuantely didn't stop execution in my terminal :( I try also to access to the file within the terminal doing `pry` but there is no `binding.pry` in my file :/ and clearly is there – Giorgia Sambrotta Apr 23 '17 at 15:06
  • @GiorgiaSambrotta Sure, terminal is a software. :) You can run `rails server` at terminal and execute code with requests from browser or `rails console` and execute some code directly from console. Also you can run plain ruby file from terminal with `ruby file.rb`. How did you run your code? – TiSer Apr 23 '17 at 16:57
  • @GiorgiaSambrotta Did you make it work? – TiSer Apr 25 '17 at 10:04
  • @TiSer i did indeed! But with the help of ruby dev friend :) `debugger` is the one that make it. The main problem: i was tring to debug the wrong method :) But all of this help me a lot to understand how to debug ruby code :D hopefully next time i'm more prepared! To answer your question: i'm running code with `rails s` and i put `debgger` directly in `file.rb` – Giorgia Sambrotta Apr 26 '17 at 11:09

0 Answers0