I don't know how to set up my routes to have the following effect:
What I have now are:
get 'change_password' => 'staffs#edit_password', as: :change_staff_password
patch 'change_password' => 'staffs#update_password', as: :change_staff_password
But it raises error: ArgumentError: Invalid route name, already in use: 'change_staff_password_staff'
The reason to do this is because the path is named "change_password_staff" without as:
. However, I want it to be "change_staff_password" with staff in the middle for clarity.
I look up match
and found match ":controller/:action/:id"
But how should I set up this to allow paths share same path name?
答案 0 :(得分:1)
我找到了答案:
match 'change_password', to: 'staffs#edit_password', via: :get
match 'change_password', to: 'staffs#update_password', via: :patch
回答@hypern:我希望路线清晰简单。
答案 1 :(得分:0)
与建议的答案相比,这是另一种方法:
resource :staffs, only: :index do
get 'change_password' => "staffs#edit_password"
patch 'change_password' => "staffs#update_password"
end
only: :index
仅作为示例,如果不需要,则应将其删除。