rails view debug

14 Mar 2015 | | rails

“I would really like to see you..really…”

It’s fairly easy to debug controllers. Use you IDE debugger, or PRY, and set your debug. But how about in views, for example the variables being rendered via ERB or HAML or whatever.

Rails has some helpers you can use: In particular, debug and to_yaml. Just go into your view code and add either(or both of the following)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def use debug
<%= debug @article %>
<p>
  <b>Title:</b>
  <%= @article.title %>
</p>

end

def use to_yaml
<%= simple_format @article.to_yaml %>
<p>
  <b>Title:</b>
  <%= @article.title %>
</p>

end
comments powered by Disqus(comments off)

Older · View Archive (32)

rake rails:update

"I just want to test out this railscast...."

Newer

notational velocity

“Scotty…how much longer before we reach Notational Velocity?.” …“Jeem…I’m giving her all she’s got! She can’t take moooch moore!