Ruby on rails 路由错误没有与[GET]匹配的路由/索引“;
我不熟悉Rails。当我尝试访问时,下面有一个路由错误http://localhost:3000/index.Ruby on rails 路由错误没有与[GET]匹配的路由/索引“;,ruby-on-rails,Ruby On Rails,我不熟悉Rails。当我尝试访问时,下面有一个路由错误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
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
[...]
以下是my route.rb文件的内容:
Rails.application.routes.draw do
root to: 'tasks#index'
resources :tasks
end
如果您能帮助我,我将非常感激…根据您提供的内容,尝试将其更改为“/”或“/tasks/index”,然后您可能会得到您想要的 或者,将此代码添加到routes.rb文件
get'/index',到:'tasks#index'
,这会将/index
路径指向任务控制器中的索引操作
Rails路由工作原理如下:当您请求“/index”时,它将尝试在routes.rb文件中查找#index route,该文件不存在,因为索引操作位于您的“tasks”控制器中(从代码中我看到)。在代码中,您将根页面(“/”)定义为“”/tasks/index“(尝试访问“/”和“/tasks/index”,它们应该是相同的)
请记住,每当您看到路由错误时,很可能您没有在routes.rb文件中定义路由
如果有任何进一步的错误/问题,请随时尝试并在此处更新
干杯:)你试过
http://localhost:3000
?您显然没有http://localhost:3000/index
。您没有/索引的路由。。。您有用于/
和/tasks
的路由,这两个路由都将在tasks controller上调用索引操作