views:

44

answers:

2

How should we separate models into sub directories? 100+ tables.

For example, for contract, there are

app/models/contract/contract.rb 
app/models/contract/contract_signer.rb

class Contract::Contract < ActiveRecord::Base
end
class Contract::ContractSigner < ActiveRecord::Base
end

I dislike it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

+1  A: 

If you want to organize your models using directories, this is perfectly normal. You will need to add this directory to your load path in environment.rb.

The only thing that looks a little odd are your class names. Why don't you just use:

class Contract < ActiveRecord::Base
end

class ContractSigner < ActiveRecord::Base
end
Beerlington
wow,this what I wanted.
qichunren
Now in Rails 3,just add:
qichunren
config.autoload_paths += %W(#{config.root}/app/models/contract) into config/application.rb. model name is still looks good. Thank you.thank you
qichunren
A: 

We've got around 130 models here and are organizing them just as you said - except we're using Contract::Base from time to time. I recommend Contract::Contract and Contract::Signer here.

Tass
I think I once tried to do namespaced models and hit issues, but I don't remember. Are there any gotchas you have to deal with?
Matchu
We use `class Contract::Base; abstract_base_class_with_table_prefix 'contract_`; end` and derive all classes in the namespace from that one.
Tass