Rails中的匹配和路线

编程入门 行业动态 更新时间:2024-10-07 10:19:06
本文介绍了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中的匹配和路线

本文发布于:2023-11-25 21:33:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路线   Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!