The first thing I do when getting a scaffolded application up is to add a unifying application.rhtml layout that has a navbar that lists all the controllers in the project. This way I can jump back and forth tweaking the controllers without going to the address bar. I just use this method in the early stages to get things rolling, before I get more into tweaking the UI the way it should be. The question is there any way of doing this automatically (kinda like AR extracts columns and db schema) from the application so that I could modify the application.rhtml once with something like <%= get_all_controllers_as_links %> and have it automatically keep up with newly added controllers etc? -- Craig Beck http://luckybonza.com AIM: Kreiggers
Craig Beck wrote:> The question is there any way of doing this automatically (kinda like > AR extracts columns and db schema) from the application so that I could > modify the application.rhtml once with something like <%= > get_all_controllers_as_links %> and have it automatically keep up with > newly added controllers etc?I''m not sure if there is a simpler way of doing it, but this ought to work: def all_controllers() result = [] ObjectSpace.each_object(Class) do |cls| if cls < ApplicationController then result << cls end end return result end
On May 10, 2005, at 4:00 PM, Florian Groß wrote:> Craig Beck wrote: >> The question is there any way of doing this automatically (kinda >> like AR extracts columns and db schema) from the application so >> that I could modify the application.rhtml once with something >> like <%= get_all_controllers_as_links %> and have it >> automatically keep up with newly added controllers etc? > > I''m not sure if there is a simpler way of doing it, but this ought > to work: > > def all_controllers() > result = [] > > ObjectSpace.each_object(Class) do |cls| > if cls < ApplicationController then > result << cls > end > end > > return result > endControllers are loaded on demand via const_missing so this will miss any controller that hasn''t handled a request. Keeping a constant in environment.rb doesn''t seem bad. However, greater introspection into controllers and actions would be nice for an easy-admin scaffolding. jeremy
On 5/11/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> Keeping a constant in environment.rb doesn''t seem bad. However, > greater introspection into controllers and actions would be nice for > an easy-admin scaffolding.Would that not help Routing also? Expanding all those :controller and :action items to real names reduceing them to constant strings .... Then cache partial url to regexes for next matcing items in a hash. For example rules app/:controller/:action/:id yoda/:controller/:action/:id would expand to: app/note/view app/note/edit app/note/destroy app/task/view yoda/ynote/yview yoda/ynote/yedit yoda/ynote/ydestroy yoda/ytask/yview that can be represented with: next_item_for[[''app'']] = /(note)|(task)/ next_item_for[[''yoda'']] = /(ynote)|(ytask)/ next_item_for[[''app'',note'']] = /(view)|(edit)|(destroy)/ next_item_for[[''app'',task'']] = /(view)/ next_item_for[[''yoda'',''ynote'']] = /(yview)|(yedit)|(ydestroy)/ # and so on .... Format restrictions like one from map.connect ''date/:year/:month/:day'', :controller => ''blog'', :action => ''by_date'', :month => nil, :day => nil, :requirements => {:year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/} can be represented like: next_item_for[[''date'']] = /(\d{4})[\/(\d{1,2)[\/(\d{1,2})]]/ or something similarly scary ;-) current values for :controller, :action and other parameters can be inferred along the way. Perhaps by keeping them in next_item_for beside regexp matching following items. Other than being written in C, I can''t find a reason why native routing should be faster, as by introspecting controller names and action names we know more about request urls. Besides Ruby regexps and hashes are also written in C. -- http://deezsombor.blogspot.com
On 11.5.2005, at 11:05, Dee Zsombor wrote:> On 5/11/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote: > >> Keeping a constant in environment.rb doesn''t seem bad. However, >> greater introspection into controllers and actions would be nice for >> an easy-admin scaffolding. > > Would that not help Routing also?Absolutely! I think it would be of immense help for example when you want all normal controller/action requests routed normally and all others through a catch-all controller for hierarchical pretty url''s of CMS-like content. Example: Controllers: * news * blog * cms /news/show/245 => traditional routing /blog/comments/2145 => traditional routing /clothes/pants/underpants => the whole shebang is passed to cms controller because clothes doesn''t match with any controller. cms controller will then parse it and display the correct page. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails