如何使用斜杠设置路由

时间:2016-04-24 07:03:59

标签: ruby-on-rails ruby

这就是我现在对我的路线所拥有的:

route

将这些格式添加到localhost:3000/appointments/new等路线的格式是什么?

2 个答案:

答案 0 :(得分:2)

使用收集路线:

resources :appointments do
  collection do
    get :confirm
    get :cancel
    get :history
  end
end

它会生成appointments/confirm等路线。

答案 1 :(得分:0)

正如上面的评论所示。您应该使用member路线:

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

如果你想要除new以外的任何其他内容。只需将其传递到only数组下。