[Rails 6] What to do when a missing a template error occurs after introducing haml [Super easy]

** Benefits of haml **

--No need for closing tags or ``` <% end%>` ``, just put it in a concise manner. ――If the indentation is not correct, an error will occur, so even if you don't like it, apply it neatly.

In addition to the above merits, there are many opportunities to use it in the field, so after studying, I introduced haml to Rails. At that time, the error `` `missing a template``` occurred and I was a little troubled, so I will leave it here as a memo. If you are looking at this page, I think that many people have already installed haml, so please jump to the solution at the bottom. For those who don't, I will also explain how to install haml.

(environment)

How to install haml

1. Add Gem

Gemfile


gem 'haml-rails'

2. The usual guy

$ docker-compose exec service name bundle

Since Docker is used for the development environment, `docker-compose exec service name` is added. This completes the introduction of haml.

Convert erb file to haml

$ docker-compose exec service name rails haml:erb2haml

This is all it takes to convert an erb file to haml.

missing a template error occurred

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.)

When I accessed localhost, I got the above error and the view disappeared.

Solution

The solution is just to restart the server. (`` `rails s```) In my case, I used docker for the development environment, so I restarted the container.

$ docker-compose restart

I think this will solve it. *** I was about to enter the labyrinth without even thinking of restarting when the field of view narrowed. *** *** I want to be careful to have a wide field of view when an error occurs.

Recommended Posts

[Rails 6] What to do when a missing a template error occurs after introducing haml [Super easy]
What to do when a javax.el.PropertyNotWritableException occurs
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
What to do when javax.batch.operations.JobStartException occurs
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
What to do if an error occurs when nokogiri enters when bundle install
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do immediately after introducing Material Design
What to do when IllegalStateException occurs in PlayFramework
[Solution] Webpacker error when introducing Vuetify to Rails6 "ActionView :: Template :: Error Webpacker can't find hello_vue ~"
[Ubuntu] What to do when MongoDB cannot be started due to a SocketException error
What to do if you get an "A server is already running." Error when you try to start the rails server
What to do if ClassNotFoundException occurs when starting Tomcat
What to do when Address already in use is displayed after executing rails s
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
[Ruby / Rails] What to do when NoMethodError appears when using a destructive method such as filter!
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
What to do if you get a "302" error in your controller unit test code in Rails
What to do if mysql2 gets a bundle install error
[Rails] What to do when the view collapses when a message is displayed with the errors method
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
[Programming beginner] What to do when rails s becomes an error in the local development environment
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if an error occurs when doing npm install axios in React + Typescript project
What to do if you get a gcc error in Docker
I get a Ruby version error when I try to start Rails.
[Rails] What to do when rails s does not respond or does not stop
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
[Rails / Docker] What to do if access is denied by the browser (localhost: 3000) after adding a gem
What to do when "npm ERR! Code ENOSELF" is displayed after npm install
What to do when Blocked Host: "host name" appears in Ruby on Rails
[Rails] What to do if you get an error saying "Could not find a JavaScript runtime." When executing the rails s command on Catalina
[Rails] What to do when the Refile image is not displayed when writing the processing at the time of Routing Error
What to do after updating Dockerfile, docker-compose.yml
[rails] How to create a partial template
A reminder when an aapt.exe error occurs
What to do when undefined method ʻuser_signed_in?'
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
[Grails] Error occurred running What to do when the Grails CLI does not start
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
What to do if ffi installation fails when launching an application in Rails
Introducing what I made when I wanted to add a header and footer to RecyclerView
[Rails] What to do when you want to generate an error that cannot be destory when foreign key restrictions are applied
[Rails] How to write when making a subquery
[Rails] Solution when migration error occurs in acts-as-taggable-on
Rails <% = expression%> Why no error occurs when empty
What to do when debugging "Source not found"
What do you use when converting to String?
What to do if the update does not take effect after deploying Rails AWS
What to do if you get a wrong number of arguments error in binding.pry
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do when routing settings do not work after building Docker environment with Laravel
What to do if you can't find your API key after deploying to Rails heroku
What to do when an error (StandardError: An error has occurred, this and all later migrations canceled:) appears in rails db: migrate