0
我有一個Client
模型,它與CronJob
模型有has_and_belongs_to_many
關係。Rails 4嵌套路線管理HABTM關係
現在給客戶啓用/取消給定自己的cron列表的能力,我想製作一個獨立於CronJobsController
app/controllers/cron_jobs_controller.rb
的控制器。我希望它在客戶機文件夾下整潔地放置命名空間,並簡單地稱其爲CronsController
(app/controllers/clients/crons_controller.rb
)。現在的問題是如何設置的路徑文件,這樣我可以得到這些路由我:
clients
- >/clients
client_crons
- >/clients/:client_id/crons
append_client_cron
- >post
- >/clients/:client_id/crons/:id
remove_client_cron
- >delete
- >/clients/:client_id/crons/:id
ř現在我的飛行有routes.rb
這一點,這是接近,但不是很
resources :clients do
namespace :clients do
resources :crons, only: ['index'] do
member do
post :append
delete :remove
end
end
end
end
導致:
append_client_clients_cron POST /clients/:client_id/clients/crons/:id/append(.:format) clients/crons#append
remove_client_clients_cron DELETE /clients/:client_id/clients/crons/:id/remove(.:format) clients/crons#remove
client_clients_crons GET /clients/:client_id/clients/crons(.:format) clients/crons#index
這裏的問題是/clients/:client_id/clients/crons/
在中間這個額外clients
。
我知道我可以將命名空間從它中取出並獲得所需的路徑,但這會使文件夾體系結構相當笨拙,因爲在各種模型上將存在許多這些HABTM關係。
或者,有沒有一種方法可以告訴路徑文件在crons資源的客戶端子文件夾中查找?
謝謝。 IDK誰降低了但這對我很好。另外,我將'member'塊更改爲'post'/',以:'crons#append''現在我發佈到'/ clients /:client_id/crons /:id' – Killerpixler