Debug output in all views
I'm currently de开发者_JS百科veloping a new Rails 3 app. All my instance variables defined in the controllers will automatically be debugged in my views. This happens both in development and production mode.
As much as this is helpful, I'd really like to get rid of that because it destroys the HTML layout partially.
For example I have in my controllers index actions:
respond_with(@articles = Article.published.order("created_at DESC").page(params[:page]).per(5))
In the view you will automatically see something similiar like the output of <%= debug @articles %>, although I never call inspect or debug in my views.
A sample picture to demonstrate the whole issue:
http://www.diigo.com/item/image/16wox/padm?size=o
My Gemfile looks like this: https://gist.github.com/1080104
You should create a method in your application helper module:
def debug_all &block
excluded_vars = ["@lookup_context", "@view_context_class", "@action_has_layout"]
controller.instance_variables.each do |var|
unless var.at(1)== "_" or excluded_vars.include?(var)
yield var
end
end
end
And in your application layout:
<% debug_all do |var| %>
<%= "variable name: #{var} " %>
<%= eval(var).inspect %>
<% end %>
精彩评论