如何從嵌套資源訪問ID?在@[email protected]
中沒有id people_id。我得到一個錯誤Couldn't find People without an ID
。提前感謝您。如何從嵌套資源獲取ids?
模型
class City < ActiveRecord::Base
has_many :peoples
end
class People < ActiveRecord::Base
belongs_to :city
end
控制器
def show
@city = City.find(session[:city_id])
@[email protected]
@[email protected](params[:id])
end
路線
resources :city, :people
resources :cities do
resources :peoples
end
對不起,這是複製粘貼錯字。但事情是它說不能找到沒有ID的人,這意味着在人的實例中沒有ID,這使我認爲這與路線有關 – katie