[英]Controller error trying to run application with ruby on rails
I am receiving an error when I try and run the application I am building with ruby on rails.当我尝试运行正在使用 ruby on rails 构建的应用程序时收到错误消息。 I am getting the following error:我收到以下错误:
ActionController::MissingExactTemplate (TestController#index is missing a template for request formats: text/html): ActionController::MissingExactTemplate(TestController#index 缺少请求格式的模板:text/html):
class TestController < ApplicationController
def index
end
end
My route.rb file:我的 route.rb 文件:
Rails.application.routes.draw do
get 'test/index'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root 'test#index'
end
My index file:我的索引文件:
<h1>Test#index</h1>
<p>Find me in app/views/test/index.html.erb</p>
I can see all the files I am referring to but don't understand this error.我可以看到我所指的所有文件,但不明白这个错误。 Can anyone shed some light on why I am getting this error?任何人都可以解释为什么我会收到此错误?
I think that is happening because the naming does not follow Rails naming conventions.我认为这是因为命名不遵循 Rails 命名约定。 Controllers should be named with plural nouns.控制器应该用复数名词命名。
Placed the controller in app/controllers/tests_controller.rb
and name it TestsController
.将控制器放在app/controllers/tests_controller.rb
并将其命名为TestsController
。 Store the index view in app/views/tests/index.html.erb
.将索引视图存储在app/views/tests/index.html.erb
。
Furthermore the config/routes.rb
needs to follow that convention too:此外, config/routes.rb
需要遵循该约定:
Rails.application.routes.draw do
root to: 'tests#index'
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.