我生成了一个控制器并更改了路由,但是打开链接会在本地服务器上产生错误。
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中的匹配和路线
发布评论