Ruby on rails 如何用斜线设置路线
这就是我现在的路线: 将其添加到路由(如Ruby on rails 如何用斜线设置路线,ruby-on-rails,ruby,Ruby On Rails,Ruby,这就是我现在的路线: 将其添加到路由(如localhost:3000/appointment/new)的格式是什么?使用收集路由: resources :appointments do collection do get :confirm get :cancel get :history end end 它将生成如上面评论中建议的约会/确认等路线。您应该使用会员路线: resources :appointments, only: [:new] do mem
localhost:3000/appointment/new
)的格式是什么?使用收集路由:
resources :appointments do
collection do
get :confirm
get :cancel
get :history
end
end
它将生成如上面评论中建议的
约会/确认
等路线。您应该使用会员
路线:
resources :appointments, only: [:new] do
member do
get :confirm
get :cancel
get :history
end
end
这将产生以下路线:
confirm_appointment GET /appointments/:id/confirm(.:format) appointments#confirm
cancel_appointment GET /appointments/:id/cancel(.:format) appointments#cancel
history_appointment GET /appointments/:id/history(.:format) appointments#history
new_appointment GET /appointments/new(.:format) appointments#new
如果您想要的不是新的
,
。只需在only
数组下传入即可。他还需要传入:id,因此我建议您使用,会员路线您的答案不会在路线中生成任何id,例如:/appoints/:id/confirm
。而是/appointment/confirm
。这是错误的。若他已经有了他想要的路线,那个么有什么理由写这个问题呢?因为他想重构它来使用资源。不完全清楚,但很明显,这是他想要做的。你的路线和图片上的OP路线有什么区别?@llya没有,除了第一条路线,无论如何都应该让他得到他想要的。至少通过会员路线,他可以得到他想要的ID。请详细说明我的回答有什么问题。OP询问了一些路线,如新建
,这是收藏
路线,而不是会员
。这只是一个重构,不是答案。请发布实际代码而不是截图。你能解释你的问题吗?您希望在输出中得到什么?我建议您至少将那些改变状态的路由设置为POST
或PUT
。过去浏览器预取链接并删除整个数据库时遇到了一些不幸的问题,因为大量的GET
请求类似于“Delete”链接。