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... -- Posted via http://www.ruby-forum.com/.
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''...
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 -- Posted via http://www.ruby-forum.com/.
Thanks both of you. I''ve found another reason to love ruby. People actually respond to posts with useful information :). -- Posted via http://www.ruby-forum.com/.
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 -- Posted via http://www.ruby-forum.com/.
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-- Posted via http://www.ruby-forum.com/.
>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. -- Posted with http://DevLists.com. Sign up and save your mailbox.
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 :-) -- Alex
On Monday, May 08, 2006, at 9:48 PM, Alex Young wrote:>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 :-)Ah - but there can be subdirectories and controllers in components, plugins, engines... -- Posted with http://DevLists.com. Sign up and save your mailbox.
You might find the code in here useful: http://svn.rails-engines.org/user_engine/trunk/app/models/permission.rb - james On 9 May 2006 01:40:14 -0000, Ryan Raaum <devlists-rubyonrails@devlists.com> wrote:> > On Monday, May 08, 2006, at 9:48 PM, Alex Young wrote: > >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 :-) > > Ah - but there can be subdirectories and controllers in components, > plugins, engines... > > > > -- > 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 * ~
James Adam wrote:> You might find the code in here useful: > http://svn.rails-engines.org/user_engine/trunk/app/models/permission.rbAh, 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 -- Posted via http://www.ruby-forum.com/.
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/models/permission.rb > >- jamesUnless 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).> >On 9 May 2006 01:40:14 -0000, Ryan Raaum ><devlists-rubyonrails@devlists.com> wrote: >> >> On Monday, May 08, 2006, at 9:48 PM, Alex Young wrote: >> >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 :-) >> >> Ah - but there can be subdirectories and controllers in components, >> plugins, engines... >> >> >> >> -- >> 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 * > ~ >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your mailbox.