views:

32

answers:

3

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:0x101f50f30 @synonyms=["application/xhtml+xml"],

and goes on like that...

Any ideas on how to get some info about the object?

A: 

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.

thenduks
I wanted to display the current controller name alongside the action name. The action name is available in controller.action_name so I thought I could use debug() to see if I could find a attribute in controller that held the name.
nibbo
So what's the problem? Look through that output (or better yet, through the ActionController docs) for the right method names and just do `<%= controller.controller_name %>` and `<%= controller.action_name %>` or whatever they end up being.
thenduks
+2  A: 

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.

mikej
+1  A: 

I saw your comment @thenduks answer.

Actually there is a method:

controller.controller_name

that returns the name of the controller.

makevoid
Thank you. Exactly what I was looking for. Just found the page in the documentation about it too.
nibbo