Anyone know an easy way of doing this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/6/07, David Fitzgibbon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Anyone know an easy way of doing this?def get_models models = [] Dir.glob( RAILS_ROOT + ''/app/models/*'' ).each do |f| models << File.basename( f ).gsub( /^(.+).rb/, ''\1'') end models end -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald wrote:> On 2/6/07, David Fitzgibbon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Anyone know an easy way of doing this? > > def get_models > models = [] > Dir.glob( RAILS_ROOT + ''/app/models/*'' ).each do |f| > models << File.basename( f ).gsub( /^(.+).rb/, ''\1'') > end > models > end > > > -- > Greg Donald > http://destiney.com/Cheers, I was hoping there would be some in-built rails method to do it, but this will do for now. Many thanks, Dave. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
this solution tracks the event of deriving from ActiveRecord::Base. it has very limited capabilities but maybe it''s helpful for you class Class @@ar_classes = [] alias :old_inherited :inherited def inherited(cls) @@ar_classes << cls if cls < ActiveRecord::Base old_inherited cls end def self.ar_classes @@ar_classes end end derived classes can be dumped with >> Class.ar_classes << 2007/2/6, David Fitzgibbon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Greg Donald wrote: > > On 2/6/07, David Fitzgibbon <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> > >> Anyone know an easy way of doing this? > > > > def get_models > > models = [] > > Dir.glob( RAILS_ROOT + ''/app/models/*'' ).each do |f| > > models << File.basename( f ).gsub( /^(.+).rb/, ''\1'') > > end > > models > > end > > > > > > -- > > Greg Donald > > http://destiney.com/ > > Cheers, I was hoping there would be some in-built rails method to do it, > but this will do for now. > > Many thanks, > > Dave. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 6, 2:50 pm, David Fitzgibbon <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Cheers, I was hoping there would be some in-built rails method to do it, > but this will do for now.You can use: ActiveRecord::Base.send :subclasses Depending on your need, you may want to use the approach of looking for the files. Rails does not load models until necessary, so unless all the models have been used, looking for subclasses through any means will not provide you with all your models. Dan Manges --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---