5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

railsでhaml変換した後にmissing a templateエラーが発生した際の対処方法

Last updated at Posted at 2020-04-04

railsでhaml:erb2hamlを実行した後にindex.html.hamlのmissing a templateが発生したので解決方法をメモ。

環境

  • rails 5.2.4

haml-railsでrails haml:erb2hamlを実行

post_app % rails haml:erb2haml
--------------------------------------------------------------------------------
Generating HAML for app/views/posts/index.html.erb...
Generating HAML for app/views/posts/_nav.html.erb...
Generating HAML for app/views/posts/_main_top.html.erb...
Generating HAML for app/views/posts/_main_bottom.html.erb...
Generating HAML for app/views/posts/_sidebar.html.erb...
Generating HAML for app/views/layouts/application.html.erb...
Generating HAML for app/views/layouts/mailer.html.erb...
Generating HAML for app/views/layouts/mailer.text.erb...
--------------------------------------------------------------------------------
HAML generated for the following files:
	app/views/posts/index.html.erb
	app/views/posts/_nav.html.erb
	app/views/posts/_main_top.html.erb
	app/views/posts/_main_bottom.html.erb
	app/views/posts/_sidebar.html.erb
	app/views/layouts/application.html.erb
	app/views/layouts/mailer.html.erb
	app/views/layouts/mailer.text.erb
--------------------------------------------------------------------------------
Would you like to delete the original .erb files? (This is not recommended unless you are under version control.) (y/n)
y
Deleting original .erb files.
--------------------------------------------------------------------------------
Task complete!
No .erb files found. Task will now exit.

rails haml:erb2hamlは成功したにもかかわらずmissing a templateエラーが発生しました。

missing a template

ActionController::UnknownFormat (PostsController#index is missing a template
 for this request format and variant.

request.formats: ["text/html"]
request.variant: []

NOTE! For XHR/Ajax or API requests, this action would normally respond with
204 No Content: an empty white screen. Since you're loading it in a web
browser, we assume that you expected to actually render a template, not
nothing, so we're showing an error to be extra-clear. If you expect 204 No
Content, carry on. That's what you'll get from an XHR or API request. Give
it a shot.):

テンプレートがないと怒られたのでファイル名やパスを確認するも間違っているところはなさそう。
ここでindex.html.hamlのファイル名をindex.html.erbに変更してみるとエラーが消えました。
ちゃんとコントローラはviews/posts/index.html.erbを呼び出しているようです。

解決方法

rails s でローカルサーバを再起動するだけ!

rails s

いくらファイル名やパスを確認してもおかしなところは見あたらず、1時間くらいなんでやー!っとなっていたので同じ境遇の人に役に立てば幸いです。

参考記事

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?