28
loading...
This website collects cookies to deliver better user experience
Stepping
, Breaking
, Evaluating
and Tracking
.debug
has been introduced in Rails 7.byebug
and new debug
gem.UserController
. Inside any Rails application, we can call the debugger by calling the byebug
method.# app/controllers/user_controller.rb
class UserController < ApplicationController
def index
name = "Hasan Tanbir"
byebug # Call to debugger
country = "Bangladesh"
end
end
[1, 7] in app/controllers/user_controller.rb
1: class UserController < ApplicationController
2: def index
3: name = "Hasan Tanbir"
4: byebug # Call to debugger
=> 5: country = "Bangladesh"
6: end
7: end
(byebug) name # variable call
"Hasan Tanbir"
debug
in Rails 7, we will have to use binding.break
method instead of byebug
method.# app/controllers/user_controller.rb
class UserController < ApplicationController
def index
name = "Hasan Tanbir"
binding.break # Call to debugger
country = "Bangladesh"
end
end
[1, 7] in app/controllers/user_controller.rb
1: class UserController < ApplicationController
2: def index
3: name = "Hasan Tanbir"
4: byebug # Call to debugger
=> 5: country = "Bangladesh"
6: end
7: end
>#0 UserController#index at ~/demo_app/app/controllers/user_controller.rb:5
(rdbg) name # variable call
"Hasan Tanbir"