I am guessing you are in development mode with class caching off :)
and that this behavior does not occur in test nor production mode ...

Try the code with either test or production if you haven't already ...
I had gone to the place you are in as well, initially my workaround
was for my class to read directories and parse .rb files to find
sub-classes - LOL and bleyech!

If you are seeing that things work just fin in test and production
modes, you and I have the same issue - I just posted my solution to
this (my fix is not pretty) to the ruby talk mailing list - it works
consistently, maybe it will help you.

Let me know if you have trouble finding it.

Max

On 5/4/11, Fearless Fool <[email protected]> wrote:
> [I posted this initially to the StackOverflow list.  There have been no
> nibbles, so I'm coming here to consult the real experts! :)]
>
> I want to display a selection list of MyModel subclasses in a view. It's
> not working yet, so for sanity checking, I included this in my view:
>
> <%= MyModel.descendants %>
>
> The first time I render this page after re-starting the server, it shows
> the list of descendants (there are six). All subsequent times, it shows
> up as an empty list [].  When invoked from the console,
> MyModel.descendants reliably returns all six subclasses.
>
> FWIW, I have a require statement in my initializers:
>
> Dir[Rails.root.join("app/models/my_models/**/*.rb").to_s].each {|f|
> require f}
> ... and I've verified that they're getting required.
>
> What the @($%& is going on?
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to