[英]Routing Error No route matches [GET] “/index”
I'm new to Rails.我是 Rails 的新手。 I've got a routing error bellow when I try to access http://localhost:3000/index.当我尝试访问 http://localhost:3000/index 时出现以下路由错误。
No route matches [GET] "/index"
Rails.root: /Users/[...]/taskleaf
Routes
Helper HTTP Verb Path Controller#Action
root_path GET / tasks#index
tasks_path GET /tasks(.:format) tasks#index
POST /tasks(.:format) tasks#create
[...]
Here is the content of my route.rb file:这是我的 route.rb 文件的内容:
Rails.application.routes.draw do
root to: 'tasks#index'
resources :tasks
end
I would be very grateful if you could help me out...如果您能帮助我,我将不胜感激...
from what you've provided, try changing it to either '/' or '/tasks/index' then you may get what you're looking for.根据您提供的内容,尝试将其更改为“/”或“/tasks/index”,然后您可能会得到所需的内容。
Or, add this code in your routes.rb file get '/index', to: 'tasks#index'
, which would direct /index
path to the index action in your tasks controller.或者,将此代码添加到您的 routes.rb 文件get '/index', to: 'tasks#index'
,这会将/index
路径指向您的任务controller 中的索引操作。
Here is how Rails routing works: when you request '/index', it'll try to find #index route in your routes.rb file, which doesn't exist since the index action lies within your 'tasks' controller (from what I've seen from your codes).这是 Rails 路由的工作原理:当您请求“/index”时,它会尝试在您的 routes.rb 文件中查找 #index 路由,因为索引操作位于您的“任务”controller中,因此该文件不存在(从什么我从你的代码中看到了)。 In the code, you defined the root page ('/') to be '/tasks/index' (try visiting '/' and '/tasks/index', they should be the same).在代码中,您将根页面('/')定义为'/tasks/index' (尝试访问'/'和'/tasks/index',它们应该相同)。
Remember, whenever you've seen a routing error, it is likely that you didn't define the route in routes.rb file请记住,每当您看到路由错误时,很可能您没有在 routes.rb 文件中定义路由
Feel free to give it a try and update here if there's any further errors/problems.如果有任何进一步的错误/问题,请随时尝试并在此处更新。
Cheers:)干杯:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.