I have two models:
Reservation:
class Reservation < ActiveRecord::Base
has_one :car_emission
end
车辆排放:
class CarEmission < ActiveRecord::Base
belongs_to :reservation
end
以及以下路由:
resources :reservations do
resources :car_emissions
end
现在,当我想创建新的car_emission时,我必须访问像这样的URL:
http://localhost:3000/reservations/1/car_emissions/new
当我想要编辑时,我必须访问:
http://localhost:3000/reservations/1/car_emissions/1/edit
有没有办法更改路由,使得我的car_emission编辑链接看起来像这样:
http://localhost:3000/reservations/1/car_emission