Ruby on Rails Debugging
-
Upload
avi-kedar -
Category
Technology
-
view
98 -
download
1
Transcript of Ruby on Rails Debugging
![Page 1: Ruby on Rails Debugging](https://reader036.fdocuments.us/reader036/viewer/2022082811/558ec34e1a28abb4468b45b6/html5/thumbnails/1.jpg)
Rails Debugging
![Page 2: Ruby on Rails Debugging](https://reader036.fdocuments.us/reader036/viewer/2022082811/558ec34e1a28abb4468b45b6/html5/thumbnails/2.jpg)
Use View Helpers
<%= debug @post %>
<%= [1, 2, 3, 4, 5].inspect %>
![Page 3: Ruby on Rails Debugging](https://reader036.fdocuments.us/reader036/viewer/2022082811/558ec34e1a28abb4468b45b6/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022082811/558ec34e1a28abb4468b45b6/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022082811/558ec34e1a28abb4468b45b6/html5/thumbnails/5.jpg)
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](https://reader036.fdocuments.us/reader036/viewer/2022082811/558ec34e1a28abb4468b45b6/html5/thumbnails/6.jpg)
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