rails view debug

14 Mar 2015 | |

"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

Older · View Archive (21)

rake rails:update

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

Newer

angularJS

"It's tax day..my printer ran out of ink as usual...oh yes...angular!..."