Rails中的匹配和路线 [英] Matching and Routes in Rails

查看:81
本文介绍了Rails中的匹配和路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一个控制器并更改了路由,但是打开链接会在本地服务器上产生错误。

I generated a controller and changed the routes but opening the links yields errors on my local server.

生成控制器和路由

rails generate controller StaticPages home about team contact

更改routes.rb

MyApp::Application.routes.draw do
  root to: 'static_pages#home'

  match '/about',    to: 'static_pages#about'
  match '/team',     to: 'static_pages#team'
  match '/contact',  to: 'static_pages#contact'
end

根路径有效,但关于,团队或联系链接均无效。这是我得到的错误:

The root path work but none of the 'about, 'team', or 'contact' links work. This is the error I get:

您不应该在未指定HTTP的情况下在路由器中使用 match 方法方法。如果要将操作公开给GET和POST,请添加通过:[:get,:post] 选项。如果要将操作公开给GET,在路由器中使用 get :代替:match controller#action做:get controller#action

"You should not use the match method in your router without specifying an HTTP method. 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""

我为什么不能使用'match'?

Why can't I use 'match'?

推荐答案

match 方法已被弃用。

match method has been deprecated.

使用 get 用于GET, post 用于POST。

Use get for GET and post for POST.

获取 / about,以: static_pages#about

这篇关于Rails中的匹配和路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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