WelcomeController#index is missing a template (...)というエラーを解決できない理由を教えてください。
rubyのバージョンは3.0.0、 mysqlのバージョンは5.7、 mysql2のバージョンは0.5.3、
bundlerバージョンは2.2.3、 railsのバージョンは5.0.7.2、
Xcodeのバージョンは12.5です。
使用機器macOS Big Sur バージョン11.2.2です。使用中のテキストエディタはAtomです。
現在food-boardというアプリを製作中です。
rails s
コマンドを実行致したら、ターミナルに以下のエラーコードが出ました。
Processing by WelcomeController#index as HTML
Completed 406 Not Acceptable in 35ms (ActiveRecord: 0.0ms)
ActionController::UnknownFormat (WelcomeController#index is missing a template for this request format and variant.
request.formats: ["text/html"]
request.variant: []):
上記のエラーコードは「WelcomeControllerの#indexメソッドにテンプレートがない」と言っておるため、
ルーティングの追加、コントローラーの追加、ビューの追加のために以下のコマンドを実行致しました。
$ rails g controller Welcome index --no-helper --no-assets
create app/controllers/welcome_controller.rb
route get 'welcome/index'
invoke erb
create app/views/welcome
create app/views/welcome/index.html.erb
food-boardフォルダには以下の2つのファイル
(app/controllers/welcome_controller.rb
、
app/views/welcome/index.html.erb
)
が追加されました。
food-board
└app
└controllers
└concerns
└application_controller.rb
└welcome_controller.rb
└views
└layouts
└welcome
└index.html.erb
└config
└routes.rb
app/controllers/welcome_controller.rb
には以下のコードが追加されました。
class WelcomeController < ApplicationController
def index
end
end
config/route.rb
には以下のコードが追加されました。
Rails.application.routes.draw do
get 'welcome/index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
app/views/welcome/index.html.erb
には以下のコードが追加されました。
<h1>Welcome#index</h1>
<p>Find me in app/views/welcome/index.html.erb</p>
config/route.rb
を以下のように編集致しました。
Rails.application.routes.draw do
root "welcome#index"
get "welcome/index"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
rails routes
コマンドの実行結果が以下の通りです。
$ rails routes
Prefix Verb URI Pattern Controller#Action
root GET / welcome#index
welcome_index GET /welcome/index(.:format) welcome#index
rails s
コマンドを再び実行致したら、ターミナルに以下のエラーコードが出ました。
Processing by WelcomeController#index as HTML
Completed 406 Not Acceptable in 35ms (ActiveRecord: 0.0ms)
ActionController::UnknownFormat (WelcomeController#index is missing a template for this request format and variant.
request.formats: ["text/html"]
request.variant: []):
下記のエラー
ActionController::UnknownFormat (WelcomeController#index is missing a template for this request format and variant.
を解決できない理由を教えていただいてもよろしいでしょうか。