Anybody know how to get a list of all your model classes from a rails environment? I''d like to do something like "ActiveRecord::Base.subclasses" but that gives me: pcollins@horatio:~/proj/foobox$ script/console Loading development environment. >> ActiveRecord::Base.subclasses NoMethodError: protected method `subclasses'' called ... Anybody know how to do this? (getting a directory listing doesn''t count) Much obliged, PMC -- 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 May 30, 9:52 pm, Pablo Collins <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''d like to do something like "ActiveRecord::Base.subclasses" but that > gives me: > > pcollins@horatio:~/proj/foobox$ script/console > Loading development environment. > >> ActiveRecord::Base.subclasses > NoMethodError: protected method `subclasses'' called ...You can bypass protected/private restrictions by using send. ActiveRecord::Base.send(:subclasses) That will only give you classes that have been loaded already.> Anybody know how to do this? (getting a directory listing doesn''t count)It may be cheating but that''s how I''ve used the directory listing before: Dir.glob("app/models/*rb") Aaron --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I was kind of hoping for a public-method solution. :-( I suppose I''ll just get the directory listing as you mention in that case. Thank you for your help friend. -Pablo Aaron wrote:> On May 30, 9:52 pm, Pablo Collins <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> I''d like to do something like "ActiveRecord::Base.subclasses" but that >> gives me: >> >> pcollins@horatio:~/proj/foobox$ script/console >> Loading development environment. >> >> ActiveRecord::Base.subclasses >> NoMethodError: protected method `subclasses'' called ... > > You can bypass protected/private restrictions by using send. > > ActiveRecord::Base.send(:subclasses) > > That will only give you classes that have been loaded already. > >> Anybody know how to do this? (getting a directory listing doesn''t count) > > It may be cheating but that''s how I''ve used the directory listing > before: > > Dir.glob("app/models/*rb") > > Aaron-- 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 -~----------~----~----~----~------~----~------~--~---
Pablo,
Dir.glob("#{RAILS_ROOT}/app/models/**/*rb").each{|m|
Dependencies.require_or_load m }
Object.subclasses_of ActiveRecord::Base
- Lourens
On 2007/06/02, at 02:58, Pablo Collins wrote:
>
> I was kind of hoping for a public-method solution. :-(
>
> I suppose I''ll just get the directory listing as you mention in
that
> case.
>
> Thank you for your help friend.
>
> -Pablo
>
> Aaron wrote:
>> On May 30, 9:52 pm, Pablo Collins
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
>> wrote:
>>> I''d like to do something like
"ActiveRecord::Base.subclasses" but
>>> that
>>> gives me:
>>>
>>> pcollins@horatio:~/proj/foobox$ script/console
>>> Loading development environment.
>>>>> ActiveRecord::Base.subclasses
>>> NoMethodError: protected method `subclasses'' called ...
>>
>> You can bypass protected/private restrictions by using send.
>>
>> ActiveRecord::Base.send(:subclasses)
>>
>> That will only give you classes that have been loaded already.
>>
>>> Anybody know how to do this? (getting a directory listing
doesn''t
>>> count)
>>
>> It may be cheating but that''s how I''ve used the
directory listing
>> before:
>>
>> Dir.glob("app/models/*rb")
>>
>> Aaron
>
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---