What are some tips for debugging Ruby erb files?

brianegge picture brianegge · Aug 29, 2009 · Viewed 11k times · Source

Currently, when I get an error on an erb template (for use with HTTPServer/cgi) I do the following:

  • If it's a small change, revert, save and retest.
  • For a large change or new file, delete or comment 1/2 the code, and retest. Perform a binary search until I've deleted/found the broken code.

The call stack doesn't seem to correspond to anything in my .rhtml file.

(erb):6:in `block in <main>'
/opt/local/lib/ruby/1.9.1/erb.rb:753:in `eval'
/opt/local/lib/ruby/1.9.1/erb.rb:753:in `result'
bin/correct.rb:45:in `block in <main>'
/opt/local/lib/ruby/1.9.1/webrick/httpservlet/prochandler.rb:26:in `call'

Answer

Peter Tascio picture Peter Tascio · Jun 15, 2017

Not sure if this is applicable to this problem but maybe it will help someone. I'm using rails 5 and if you put

    <% debugger %>

in your html.erb file it will pause the terminal window that your rails server is running in. From there you can debug whatever params or variables your html.erb file has.