In one of my templates I want to take a closer look at the controller object using the debug() helper.
It is said to produce YAML suitable for HTML output.
Running <%= debug(controller) %> does, however, not produce anything I call readable.
It begins with:
#<ClubsController:0x104467378 @_request=#<ActionController::Request:0x104467648 @accepts=[#<Mime::Type:0x1开发者_如何学运维01f50f30 @synonyms=["application/xhtml+xml"],
and goes on like that...
Any ideas on how to get some info about the object?
The debug
helper is primarily intended to be used with objects that provide an implementation of to_yaml
(such as ActiveRecord models). If the object passed doesn't respond to to_yaml
(as is the case with passing a controller object in your example) then debug
gives you the result from calling inspect
on that object.
I saw your comment @thenduks answer.
Actually there is a method:
controller.controller_name
that returns the name of the controller.
What's not readable about that? It's the standard ruby inspection syntax... If you really need something 'more readable' then you'll have to write a method on your controller (temporarily, most likely) that simply exposes it's instance variables in another format.
Perhaps it would help if you noted what you want to see in the controller instance.
精彩评论