0
我有一個STI模型,有超過20個子類,我需要將它們全部指向我的路線中的父控制器。我一直在定義路線中的每一條路線,但這確實是低效的,而不是DRY。這是它現在的樣子。DRY路線單控制器軌道4 STI模型
resources :red_master_models, :controller => 'master_models'
resources :green_master_models, :controller => 'master_models'
resources :yellow_master_models, :controller => 'master_models'
resources :purple_master_models, :controller => 'master_models'
resources :orange_master_models, :controller => 'master_models'
resources :grey_master_models, :controller => 'master_models'
resources :indigo_master_models, :controller => 'master_models'
resources :blue_master_models, :controller => 'master_models'
我覺得我應該能夠循環所有的子類,並更簡單地定義它。這是我試過的......但它不起作用。
MasterModel.subclasses.each do |master_model|
resources master_model.name.underscore.to_sym, :controller => 'master_models'
end
什麼是需要我的模型的語法? – NothingToSeeHere
我已經搜索如何明確要求模型,我很茫然。你有什麼見解嗎? – NothingToSeeHere
對不起,沒有看到您的第一條評論。爲了測試理論,我首先要做到這一點: 'puts'here' MasterModel.subclasses.each do | master_model | puts master_model.to_s resources master_model.name.underscore.to_sym,:controller =>'master_models' end ' – Brad