简体   繁体   English

如何在routes.rb中修改URL

[英]How to modify url in routes.rb

I want to map a url '/admin/update_admin/1' but my url maps to '/admin/1/update_admin' for the provided resources 我想将URL映射为“ / admin / update_admin / 1”,但将URL映射为“ / admin / 1 / update_admin”以获取所提供的资源

resources :admin
  member do
    post :update_admin
  end
end

How to get the expected url? 如何获得预期的网址? Because of wrong url I am getting the error 由于网址错误,我得到了错误

The action '1' could not be found for AdminController

If you want such url - you should try to use collection instead: 如果您想要这样的网址-您应该尝试使用collection代替:

resources :admin
 collection do
  match "update_admin/:id" => "admin#update_admin", :via => :post
 end
end

I am not sure for correct syntax (You can look it here: Routing in Rails ) 我不确定语法是否正确(您可以在此处查看: Rails中的路由

Hope it will help you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM