Ruby on Rails Debugging

6
Rails Debugging

Transcript of Ruby on Rails Debugging

Page 1: Ruby on Rails Debugging

Rails Debugging

Page 2: Ruby on Rails Debugging

Use View Helpers

<%= debug @post %>

<%= [1, 2, 3, 4, 5].inspect %>

Page 3: Ruby on Rails Debugging

Use The Logger

logger.debug "Person attributes hash: #{@person.attributes.inspect}“

logger.info "Processing the request...“

logger.fatal "Terminating application, raised unrecoverable error!!!"

Log levels: (debug|info|warn|error|fatal)

Page 4: Ruby on Rails Debugging

Use Rails Debugger1. install group :development do

gem 'debugger' end

2. Call ‘debugger’ action inside ruby code to add break point

3. Run ‘rails s --debugger’

Page 5: Ruby on Rails Debugging

List Command1. Use list or l (shorthand)

2. ‘l=‘ to see the current breakpoint with 5 previous and 5 next code lines

3. ‘l’ to see the next 10 code lines

4. ‘l-’ to see the previous 10 code lines

Page 6: Ruby on Rails Debugging

More Commands

***Use ‘help’!***

1. ‘instance_variables’ – return array of all the instance variables

2. ‘next’ – execute the current line

3. ‘c’ (continue) – resume the execution

4. ‘where’ - see the stacktrace