【问题标题】:Getting an error with routes [ruby on rails]路线出错 [ruby on rails]
【发布时间】: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


【解决方案1】:

是的,您应该使用get 或指定match '/signup', :to => 'users#new', via: :get。基本上这就是错误所说的。

您可以查看文档:Rails Routing from the Outside In

【讨论】:

  • 谢谢你成功了。我正在使用 via: [:get] 这也给了我一个错误
  • 您可以使用变体via: :getvia: [:get]
猜你喜欢
  • 2011-02-15
  • 2011-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多