我的路線文件是:嵌套資源3
resources :countries do
resources :regions do
resources :appartments
end
end
型號:
Country: has_many :regions
Region: belongs_to :country, has_many :appartments
Appartment: belongs_to: region
Region_controller:
def index
@country = Country.find(params[:country_id])
@regions = @country.regions
end
def show
@country = Country.find(params[:country_id])
@region = @country.regions.find(params[:id])
end
問:
我想上顯示個公寓區域頁面。我的區域控制器中的最佳做法是什麼?
隨意忽略我的編輯,@apneadiving在我做之前做到了。你想展示屬於該地區的公寓嗎? –