the naming of STI tables

File this under mild pedantry, but it's been bugging me. Assume I want to store different kinds of fruit in an STI table. My approach works, but I end up referring to "fruit_bases" throughout my code where I'd really prefer just "fruits".

What I've got is something like:

class Fruit < ActiveRecord::Base   belongs_to :basket end

class Apple < Fruit end

class Basket < ActiveRecord::Base   has_many :fruits end

Ref: "Single Table Inheritance" ActiveRecord::Base

Robb Kidd wrote in post #1050675:

class Fruit < ActiveRecord::Base   belongs_to :basket end

class Apple < Fruit end

class Basket < ActiveRecord::Base   has_many :fruits end

Ref: "Single Table Inheritance" ActiveRecord::Base

Robb: Pardon -- Although my code shows it, I should have stated explicitly that I am sticking all the STI sub-classes in a Fruit module and app/model/fruit subdirectory. I envision enough Fruit sub-classes that I don't want them all in the toplevel app/model directory.

I did notice this. You can still stick fruit.rb, apple.rb and your other fruit classes in app/models/fruit and prevent automatic namespacing which you are working around with your module. It involves explicitly adding app/models/fruit to Rails’ autoload paths.

Find the following line in config/application.rb:

config.autoload_paths += %W(#{config.root}/lib)

…and change it to…

config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/models/fruit)

I am not entirely certain this is the cleanest, most Railsy way, but it was the poison I picked over the complexity of unnecessary modules or namespaces. I can live with a path added to config.