0

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:

Error I am receiving

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?

3
  • What is the full name of the index file (with extensions) and where is it located ? Commented Dec 26, 2019 at 21:26
  • @Viktor the index file is named index.html.erb and is located in the sampleApp/views/test/index.html.erb Commented Dec 26, 2019 at 22:56
  • Are you sure you saved the index file with that content? An error like that could occur when there's no content inside the view Commented Dec 26, 2019 at 23:48

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.