简体   繁体   English

路由错误没有路由匹配[GET]

[英]Routing Error No route matches [GET]

I have made a controller and get the following error message 我做了一个控制器,并收到以下错误消息

Routing Error No route matches [GET] "handm/index" 路由错误没有路由匹配[GET]“ handm / index”

(these are the headings of the error table) (这些是错误表的标题)

Routes Routes match in priority from top to bottom Helper HTTP Verb Path Controller#Action Path / Url 路由路由从上到下优先级匹配Helper HTTP动词路径控制器#Action路径/网址

(this is the contents) handm_index_path GET /handm/index(.:format) handm#index root_path GET / handm#index Request Parameters: (这是内容)handm_index_path GET /handm/index(.:format)handm#index root_path GET / handm#index请求参数:

could somebody explain what this error means please. 有人可以请解释这个错误的含义。 below is my routes file. 下面是我的路线文件。

Rails.application.routes.draw do
  get '/handm/index' 
  root :to => "handm#index"
end
Rails.application.routes.draw do      
  get '/handm/index', to: 'handm#index'
  root :to => "handm#index"
end

i already solved mine, 我已经解决了我的问题

you dont need to put http://127.0.0.1:3000/index 您不需要放http://127.0.0.1:3000/index

just this http://127.0.0.1:3000/ since you tell rails to make you index as root. 只是这个http://127.0.0.1:3000/,因为您告诉rails使您以root身份进行索引。

but you will have get a problem regarding javascript, to sovle you need to edit your application.js 但您会遇到有关javascript的问题,要解决此问题,您需要编辑application.js

edit this line //= require_tree . 编辑此行// = require_tree。 to = require_tree . 到= require_tree。

hope this will help 希望这会有所帮助

Try below code: 试试下面的代码:

routes.rb routes.rb

Rails.application.routes.draw do
  get '/handm/index' => 'handm#index'
  root :to => "handm#index"
end

handm_controller.rb handm_controller.rb

class HandmController < ApplicationController 
  def index 
    ...
  end 
end

views/handm/index.html.erb views / handm / index.html.erb

<h1>In index page</h1>

Start your server by command: 通过命令启动服务器:

rails server

and hit url: 然后点击网址:

localhost:3000

or 要么

localhost:3000/handm/index

The error means that the specified route or path doesn't exist. 该错误表示指定的路由或路径不存在。 So, the solution is to change it to a valid path. 因此,解决方案是将其更改为有效路径。 We can only guess at the paths supported by your Rails app, but /handm#index is plausible: 我们只能猜测您的Rails应用程序支持的路径,但是/handm#index是合理的:

Rails.application.routes.draw do
  get '/handm/index' => 'handm#index'
  root :to => "handm#index"
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM