Forum: Ruby on Rails Listing Actions

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.
36130a59dd684a72011cf7ceeea6bdb8?d=identicon&s=25 Erich L. Timkar (Guest)
on 2006-05-05 22:08
OK, call me crazy, but am I the first one to want to list out the
actions that are available @ runtime?   Anyone else come across this
yet?  Am I crazy?  Well, yes, but...
27f8beb57f4d56d328749b51ac886d2c?d=identicon&s=25 Kian (Guest)
on 2006-05-05 22:33
(Received via mailing list)
Erich L. Timkar <erichtimkar@...> writes:

>
> OK, call me crazy, but am I the first one to want to list out the
> actions that are available  <at>  runtime?   Anyone else come across this
> yet?  Am I crazy?  Well, yes, but...
>

How about in your view:

<%= debug (@controller.class.instance_methods -
       ApplicationController.instance_methods) %>

Seems to work for me.

Interestingly, it showed me not only my action methods, but also some of
the
methods in my helpers. I guess I should make those 'private'...
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-05-06 01:33
Kian wrote:
> Erich L. Timkar <erichtimkar@...> writes:
>
>>
>> OK, call me crazy, but am I the first one to want to list out the
>> actions that are available  <at>  runtime?   Anyone else come across this
>> yet?  Am I crazy?  Well, yes, but...
>>
>
> How about in your view:
>
> <%= debug (@controller.class.instance_methods -
>        ApplicationController.instance_methods) %>
>
> Seems to work for me.
>
> Interestingly, it showed me not only my action methods, but also some of
> the
> methods in my helpers. I guess I should make those 'private'...

Try this instead:

<%= debug (@controller.class.instance_methods -
        @controller.class.hidden_actions) %>

--
Josh Susser
http://blog.hasmanythrough.com
36130a59dd684a72011cf7ceeea6bdb8?d=identicon&s=25 Erich L. Timkar (Guest)
on 2006-05-06 19:38
Thanks both of you.  I've found another reason to love ruby.  People
actually respond to posts with useful information :).
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-05-06 21:02
Erich L. Timkar wrote:
> Thanks both of you.  I've found another reason to love ruby.  People
> actually respond to posts with useful information :).

Yes, that's why many of us love Ruby and Rails.  By the way, I goofed a
bit.  Try Foo.public_instance_methods - Foo.hidden actions. (Odds of
getting code right when composed in an email: 50%).

--
Josh Susser
http://blog.hasmanythrough.com
0c9569cf1cf5e1345b00c87f413effe7?d=identicon&s=25 Erich L. Timkar (Guest)
on 2006-05-08 20:34
The other reason I like rails/ruby is, based on your response, I tried
"public_instance_methods" and it worked. :)

So, just to be a pest, anyway to determine dynamically the controllers
available @ runtime? I checked the ADWROR and Rails Recipes with no
luck.



Josh Susser wrote:
> Erich L. Timkar wrote:
>> Thanks both of you.  I've found another reason to love ruby.  People
>> actually respond to posts with useful information :).
>
> Yes, that's why many of us love Ruby and Rails.  By the way, I goofed a
> bit.  Try Foo.public_instance_methods - Foo.hidden actions. (Odds of
> getting code right when composed in an email: 50%).
>
> --
> Josh Susser
> http://blog.hasmanythrough.com
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Ryan Raaum (Guest)
on 2006-05-08 22:21
(Received via mailing list)
>So, just to be a pest, anyway to determine dynamically the controllers
>available @ runtime? I checked the ADWROR and Rails Recipes with no
>luck.

Much trickier (to my knowledge anyways).  If someone has a one-liner
that lists all the controllers, I'm excited to hear about it.

As I understand it, controllers aren't loaded until they are called the
first time, so to find all the controllers, I

1. Query the ObjectSpace object for all loaded Classes descending from
::ActionController::Base
2. Query the Routes for all controllers named in routes
3. Get the Rails::Configuration object and pull the controller_paths
from there and then try to load controller objects inflected from the
file names.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-05-08 22:50
(Received via mailing list)
Ryan Raaum wrote:
>>So, just to be a pest, anyway to determine dynamically the controllers
>>available @ runtime? I checked the ADWROR and Rails Recipes with no
>>luck.
>
>
> Much trickier (to my knowledge anyways).  If someone has a one-liner
> that lists all the controllers, I'm excited to hear about it.
Dir[File.join(File.expand_path(RAILS_ROOT), 'app', 'controllers', '**',
'*.rb')].collect{|f| File.basename(f, '.rb')}

Something along those lines, anyway :-)
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Ryan Raaum (Guest)
on 2006-05-09 03:42
(Received via mailing list)
On Monday, May 08, 2006, at 9:48 PM, Alex Young wrote:
>
>Something along those lines, anyway :-)

Ah - but there can be subdirectories and controllers in components,
plugins, engines...
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-05-09 10:51
(Received via mailing list)
You might find the code in here useful:

  http://svn.rails-engines.org/user_engine/trunk/app...

- james

On 9 May 2006 01:40:14 -0000, Ryan Raaum
<devlists-rubyonrails@devlists.com> wrote:
> >Dir[File.join(File.expand_path(RAILS_ROOT), 'app', 'controllers', '**',
> Posted with http://DevLists.com.  Sign up and save your mailbox.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
* J *
  ~
0c9569cf1cf5e1345b00c87f413effe7?d=identicon&s=25 Erich L. Timkar (Guest)
on 2006-05-09 19:54
James Adam wrote:
> You might find the code in here useful:
>   http://svn.rails-engines.org/user_engine/trunk/app...

Ah, I had thought about checking the controller path but having done
servlet development mostly, I've undergone years of operant conditioning
teaching me, "File Access BAD!!" <slap>

Thanks James
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Ryan Raaum (Guest)
on 2006-05-09 21:42
(Received via mailing list)
On Tuesday, May 09, 2006, at 9:49 AM, James Adam wrote:
>You might find the code in here useful:
>
>  http://svn.rails-engines.org/user_engine/trunk/app...
>
>- james

Unless I'm horribly misreading that code, it still will miss any
controllers in components, etc.

One way to know if you've truly found all the available controllers is
if the method chosen finds the Rails::InfoController (which is present
in every 1.1+ (1.0+?) app).
This topic is locked and can not be replied to.