Rails根路由索引

我还是Ruby on Rails的新手,并且一直试图将我的默认路由配置几个小时但没有成功。 目前我的路线设置为

root :to => 'proto#index' 

但是我不知道要创建/编辑哪个文件。 我完全失去了。 我从服务器收到的错误是

 AbstractController::ActionNotFound (The action 'index' could not be found for ProtoController): 

我在找什么文件?

您正在寻找app / controllers / proto_controller.rb

它应包含以下内容

 class ProtoController < ApplicationController def index end end 

然后你想在app / views / proto / index.html.erb上创建一个包含页面html的文件。

你应该检查几件事。

你有一个名为“proto”的控制器吗?

如果是这样,你的原型控制器中是否有index操作?

理想情况下,您的原型控制器应该是……

 class ProtoController < ApplicationController def index @protos = Proto.all end end 

我认为是app/controllers/proto_controller.rb

rails约定是在控制器中复数模型名称。

root :to => 'proto#index' #index root :to => 'proto#index'应该在config / routes.rb中

应该在app / controllers / proto_controller.rb中定义ProtoController

 class ProtoController < ApplicationController def index # ... respond_to do |format| format.html end end end 

此操作将查找app / views / proto / index.html.erb定义的模板并将其呈现出来。