【发布时间】:2020-04-10 08:16:21
【问题描述】:
我正在阅读 Michael 的 Hartl Ruby on Rails 教程,但在 routes.rb 中出现错误。
这是我在 routes.rb 中的代码
Rails.application.routes.draw do
get 'users/new'
match '/signup', :to => 'users#new'
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
root :to => 'pages#home'
end
这是我得到的错误:
You should not use the `match` method in your router without specifying an HTTP method. (ArgumentError)
If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.
If you want to expose your action to GET, use `get` in the router:
Instead of: match "controller#action"
Do: get "controller#action"
我很困惑。我应该使用get“controller#action”还是匹配?使用 match 时正确的代码是什么?
【问题讨论】:
-
作为错误状态和docs explain,您需要另一个用于 http 动词的参数。
标签: ruby-on-rails ruby get routes match