Wednesday, May 4, 2011

[Rails] MyModel.descendants returns [] in a view after the first call?

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate