How to debug the Discourse?

(Mike) #1


I would some information on learning how to debug Discourse, setting up a few breakpoints, and just sort of poke around. I’m no expert in Ruby or Rails.

I am using RubyMine. I’ve downloaded the repo, and installed all the bundles and gem packages.

I try to run for example the file “badges_controller.rb” and I get the error message:

/Users/[user]/Documents/discourse/app/controllers/badges_controller.rb:1:in `<top (required)>': uninitialized constant ApplicationController (NameError)
	from -e:1:in `load'
	from -e:1:in `<main>'

I don’t even know why I expect it to run as I am not connected to a database, I notice the message:

7:26:35 PM Database connections detector
           Database connection properties are detected.
           Click here to let RubyMine discover and setup new data sources. (show balloon)

What do I have to do to set up a local dev environment where I can begin to use RubyMine debugger on the app?

thanks :smiley:

(Régis Hanol) #2

Maybe @riking can help? I think he’s using RubyMine too.

(Kane York) #3

I don’t use the IDE debugger. I insert a binding.pry, auto-save the file (tabbing out will do this), then either do the request again (if it’s an auto-reload file) or restart the bundle exec rails s if it’s not.

(Mike) #5

Sounds interesting. Could you pls give me step by step instructions? :smiley:

(James Kiesel) #6
  • Add binding.pry (or byebug, which I prefer; both are included in Discourse’s Gemfile I believe) as a line of code to the place in your .rb file you’d like to stop execution
    (like so:
def method
  binding.pry # or byebug
  • Save your changes to that file (ctrl+s)
  • Navigate to the discourse page in your browser which will reach that line of code
  • Go to your server log (the console you ran rails s in, and enter any command(s) you like.
  • Once you’re done you can type exit (or continue for byebug), to continue execution of the request normally.

As Riking stated above, some files are not reloaded every request (a good example would be an initializer, or a config file), in which case you’ll need to stop your rails s process and restart it in order to pick up the changes.

Check out some docs on pry or byebug for more info.