Html.haml vs haml templates in Rails

What is the difference between using presentation templates in Rails like ".html.haml" and just ".haml"? For example, photos show.html.haml
against
show.haml

Are there any special advantages to using one over the other? Or is one of them a standard practice? The same question applies to other types of patterns, for example, ".erb".

+6
source share
1 answer

The format matters when you use Rails automatic responders. See http://api.rubyonrails.org/classes/ActionController/MimeResponds.html#method-i-respond_with .

So, for example, with:

 class CarsController < ActionController::Base respond_to :html, :js def index respond_with Car.all end end 

The application will display app/views/cars/index.html.erb and app/views/index.js.erb when viewing http://localhost:3000/cars and http://localhost:3000/cars.js respectively.

It’s also an established agreement in Rails-land, so it’s just a good idea to do it anyway, even if you don’t use answering machines.

+5
source

Source: https://habr.com/ru/post/907286/


All Articles