据我所知,我了解Rails 4不支持匹配关键字。
但是我想制作一个类似于
的默认通用路线match ':controller(/:action(/:id))(.:format)', :via => :get
当我在routes.rb中使用上面的代码时,它会抛出以下错误:
Missing :action key on routes definition, please check your routes
有人可以帮我解决如何在Rails 4中实现这一点。
答案 0 :(得分:0)
是的,Rails Routing from the Outside In指南
支持它3.7 HTTP动词约束
通常,您应该使用get,post,put,patch和delete方法来约束到特定动词的路由。您可以将match方法与:via选项一起使用以匹配多个动词:
将照片'匹配到:'照片#show',通过:[:get,:post]
您可以使用via :: all:
将所有动词与特定路线匹配匹配'照片'到:'照片#show',via :: all
并从文档中
http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Base.html#method-i-match
# sets :controller, :action and :id in params
match ':controller/:action/:id', via: [:get, :post]
如果您将此行添加到路线中:
match ':controller/:action/(:id)', via: :get
它将产生以下路线:
Prefix Verb URI Pattern Controller#Action
GET /:controller/:action(/:id)(.:format) :controller#:action