[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 null byte error occurs
What to do when a javax.el.PropertyNotWritableException occurs
What to do when rails creates a 〇〇 2.rb file
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 if the image posted by refile disappears after setting a 404 error page in Rails
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 if an ActionController :: UnknownFormat error occurs
What to do when Address already in use is displayed after executing rails s
What to do if you get a port error when docker-compose up on Mac
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
How to resolve Missing Template error when implementing comment function
[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
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
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 if you get a DISPLAY error in gym.render ()
What to do when you become a Problem During Content Assist
What to do after Vagrant install
What to do if an error occurs in VS Code when importing a django module or your own module installed by pip install
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
[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
What to do if you get an error when you hit Heroku logs
[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?'
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do when you want to delete a migration file that is "NO FILE"
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
What to do when rails db: seed does not reflect in the database
[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] How to write when making a subquery