How does Rails find models and controllers? How can I get it to load more models?
Posted
by
David
on Stack Overflow
See other posts from Stack Overflow
or by David
Published on 2010-12-26T09:43:40Z
Indexed on
2010/12/26
9:54 UTC
Read the original article
Hit count: 287
I'm trying to create a non-ActiveRecord model in app/models/gamestate.rb
. Then inside my controller (PlayController) I should be able to do GameState.new
, right? No go:
NameError (uninitialized constant PlayController::GameState):
app/controllers/play_controller.rb:23:in `play'
(at least in the development environment)
But! If I do have a model called app/models/play.rb
, then it's automatically loaded and I can do Play.new
.
So my question is: how does Rails know which classes to load? What sort of name mangling does it do to get from play#action
to PlayController
to app/controllers/play_controller.rb
to app/models/play.rb
?
It seems awfully fragile, but maybe a better understanding of how this works would help.
And finally, how can I get it to load app/models/gamestate.rb
?
© Stack Overflow or respective owner