用于导轨的导轨中的get
与match
有什么区别?导轨之间的区别与差异
例如,使用get
,我可以写
get '/users' "users#index", as => 'all_users'
,不能做我使用match
像下面一样的东西:
match '/users' => 'users#index', as => 'all_users'
当我应该选择一个,为什么?
用于导轨的导轨中的get
与match
有什么区别?导轨之间的区别与差异
例如,使用get
,我可以写
get '/users' "users#index", as => 'all_users'
,不能做我使用match
像下面一样的东西:
match '/users' => 'users#index', as => 'all_users'
当我应该选择一个,为什么?
get
定义了允许通过HTTP GET
方法请求的路由。 get
是首选,如果只是想以一个方法作出回应:
get 'users', to: 'users#index', as: 'all_users'
如果你想你可以使用match
多种方法作出回应,但仍应定义为安全起见,允许的方法:
match 'user', to: 'users#index', as: 'all_users', via: [:get, :post]
从Rails Docs引用:
如果不指定HTTP方法,则不应在路由器中使用
match
方法。