valk
valk

Reputation: 9894

Using binding.pry in Rails app's view or partial

Pry is quite amazing in my R3 app. But any chance I can use

<% binding.pry %> 

in a view or a partial like I did previously with

<% debugger %>

This doesn't seem to work. Thanks.

Upvotes: 22

Views: 21948

Answers (4)

Trevor T
Trevor T

Reputation: 21

I realize this question is now dated, but wanted to raise one other possibility here. It is also possible that your app is breaking before reaching the line of code in which you've placed <%binding.pry%>. If you are not hitting pry (and have confirmed that it is in your Gemfile and that you've run bundle install), consider moving <%binding.pry%> a few lines higher up in your code. If you still do not hit it, consider repeating this process. If you've worked your way to the first line of the view and still aren't hitting pry, try working backward to the controller action that controls rendering this view. If pry is indeed bundled, a common reason for not hitting pry is the app breaking. Again, posting the error here always helps.

Upvotes: 2

Prashanth
Prashanth

Reputation: 81

<% binding.pry %> works well.

It doesn't work only if you didn't install pry-rails gem in your rails app.

Please post the error that you are facing if use <% binding.pry %> such that I can elaborate it more.

Upvotes: 8

Dan
Dan

Reputation: 389

Or even better, I like to pass in PRY as an environmental var so I don't have to delete all the requires!

<% binding.pry %>

&&

$ PRY=true rails s

Upvotes: 0

Abe Voelker
Abe Voelker

Reputation: 31622

It's always worked for me... you might need to require it.

<% require 'pry'; binding.pry %>

Upvotes: 31

Related Questions