如何从嵌套资源访问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