Forum: Ruby on Rails Accessing a controller variable?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A04eeb60e2c500bbcebdff8c17281f1a?d=identicon&s=25 Parama (Guest)
on 2007-06-18 01:01
(Received via mailing list)
I'm looking to find a way to access the data inside  "@controller".
i.e. when you have @controller.inspect you will see a list of all data
in them.

Are there anyway to do this?

My real aim is to get the name of the action automatically.
4c3acdc3d93f54cc7a7281780ec8a4ee?d=identicon&s=25 shai (Guest)
on 2007-06-18 09:56
Parama wrote:
> I'm looking to find a way to access the data inside  "@controller".
> i.e. when you have @controller.inspect you will see a list of all data
> in them.
>
> Are there anyway to do this?
>
> My real aim is to get the name of the action automatically.

if you have a class controller such as

ExampleController

you can access it by accessing it, really.
ruby-render this (the ExampleController class will need to exist
obviously):


ExampleController.methods.join(' , ')


...and if you want it in a variable @controller, assign it.
@controller = ExampleController
and then, @controller.methods.inspect

hth
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2007-06-18 12:46
(Received via mailing list)
Hi --

On Sun, 17 Jun 2007, Parama wrote:

>
> I'm looking to find a way to access the data inside  "@controller".
> i.e. when you have @controller.inspect you will see a list of all data
> in them.
>
> Are there anyway to do this?
>
> My real aim is to get the name of the action automatically.

Have a look at the docs for ActionController::Base.  There's an
attribute action_name, and various other methods for extracting
information.


David

--
* Books:
   RAILS ROUTING (new! http://safari.awprofessional.com/9780321509246)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)
A04eeb60e2c500bbcebdff8c17281f1a?d=identicon&s=25 Parama (Guest)
on 2007-06-18 21:12
(Received via mailing list)
Thanks David. it works
This topic is locked and can not be replied to.