简体   繁体   中英

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. I am getting the following error:

我收到的错误

ActionController::MissingExactTemplate (TestController#index is missing a template for request formats: text/html):

class TestController < ApplicationController
  def index
  end
end

My route.rb file:

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. Controllers should be named with plural nouns.

Placed the controller in app/controllers/tests_controller.rb and name it TestsController . Store the index view in app/views/tests/index.html.erb .

Furthermore the config/routes.rb needs to follow that convention too:

Rails.application.routes.draw do
  root to: 'tests#index'
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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