rails 4 中的路由问题关于匹配关键字在 rails 3 中工作 [英] route issue in rails 4 about match keyword working in rails 3

查看:35
本文介绍了rails 4 中的路由问题关于匹配关键字在 rails 3 中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 rails 3 中匹配关键字有效但在 rails 4 中匹配关键字不适用于路由

In rails 3 match keyword is working but in rails 4 match keyword is not working for routes

如何在 rails 4 中定义这些路由

how can i define these routes in rails 4

此代码段在 rails 3 中工作

this code segment is working in rails 3

match 'admin', :to => 'access#menu'

match 'show/:id', :to => 'public#show'

match ':controller(/:action(/:id(.:format)))'

我需要 rails 4 的通用公式,如 rails 3

i need generic formula for rails 4 like in rails 3

 match ':controller(/:action(/:id(.:format)))'

推荐答案

Rails 4 移除了通用的 match,您现在必须指定您希望它响应哪个动词.通常,您将路由定义为:

Rails 4 removed generic match, you now have to specify which verb you want it to respond to. Typically you'd define your routes as:

get ':controller(/:action(/:id(.:format)))' => 'foo#matcher'

如果你想让它使用 match 来获取多个动词,你可以这样做:

If you want it to use match to get multiple verbs, you can do it like this:

match ':controller(/:action(/:id(.:format)))' => 'foo#matcher', via: [:get, :post]

这篇关于rails 4 中的路由问题关于匹配关键字在 rails 3 中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆