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.
Erich L. Timkar (Guest)
on 2006-05-06 00: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...
Kian (Guest)
on 2006-05-06 00: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'...
Josh S. (Guest)
on 2006-05-06 03: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 S.
http://blog.hasmanythrough.com
Erich L. Timkar (Guest)
on 2006-05-06 21:38
Thanks both of you.  I've found another reason to love ruby.  People
actually respond to posts with useful information :).
Josh S. (Guest)
on 2006-05-06 23: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 S.
http://blog.hasmanythrough.com
Erich L. Timkar (Guest)
on 2006-05-08 22: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 S. 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 S.
> http://blog.hasmanythrough.com
Ryan R. (Guest)
on 2006-05-09 00: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.
Alex Y. (Guest)
on 2006-05-09 00:50
(Received via mailing list)
Ryan R. 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 :-)
Ryan R. (Guest)
on 2006-05-09 05:42
(Received via mailing list)
On Monday, May 08, 2006, at 9:48 PM, Alex Y. wrote:
>
>Something along those lines, anyway :-)

Ah - but there can be subdirectories and controllers in components,
plugins, engines...
James A. (Guest)
on 2006-05-09 12: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 R.
<removed_email_address@domain.invalid> 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
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
* J *
  ~
Erich L. Timkar (Guest)
on 2006-05-09 21:54
James A. 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
Ryan R. (Guest)
on 2006-05-09 23:42
(Received via mailing list)
On Tuesday, May 09, 2006, at 9:49 AM, James A. 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.