Forum: Ruby on Rails "model :modelX" deprecated

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7b2a4ea7a2c486b1b0ceab3c6d4680d9?d=identicon&s=25 Joe Cairns (diregnome)
on 2007-02-15 20:49
(Received via mailing list)
Hi, my app is using single table inheritance and has run into the
"uninitialized constant" error once I remove the model call.

I set up my STI using the instructions in the wiki, which I am
guessing are badly out of date now:

http://wiki.rubyonrails.org/rails/pages/SingleTabl...
"If you have an "uninitialized constant" error:
Note: Rails must 'see' the file containing the STI classes before it
can use them, otherwise you'll end up with an "uninitialized constant"
error. This can be a problem if the name of the class and the name of
the file defining it are not the same, e.g. you have the model
'Manager' in the file 'employees.rb'. Rails will not be able to divine
the filename from the class name in this case.

An easy way to do fix this is to add "model :employees" to your
application.rb controller, where 'employees' is the name of the file
containing the STI class minus the extension (so in this case, the
model would be contained in a file named 'employees.rb'.) This forces
Rails to load that file and 'see' all the models you have defined in
it, and it will then know of your STI classes when you go to use
them."

Short of adding a file for each child model in the inheritance tree,
does anyone have a work around for this?
13e4ba7f654dbbdd186d702c06c8b24c?d=identicon&s=25 Morten (Guest)
on 2007-02-16 11:18
(Received via mailing list)
On 15 Feb., 20:47, "Joe Cairns" <joe.cai...@gmail.com> wrote:
> Hi, my app is using single table inheritance and has run into the
> "uninitialized constant" error once I remove themodelcall.
>
> I set up my STI using the instructions in the wiki, which I am
> guessing are badly out of date now:
>
...
>
> Short of adding a file for each childmodelin the inheritance tree,
> does anyone have a work around for this?

Assuming that all your STI classes are defined in app/model/modelx.rb
try using

  require 'modelx'

In application.rb rather than

  model :modelx
This topic is locked and can not be replied to.