What is the difference between using view templates in Rails as '.html.haml' and as simply '.haml'?
For example,show.html.haml
vsshow.haml
Are there any particular advantages of using one over the other? Or is one of them a standard practice? The same question goes for other types of templates as well, like '.erb'.
The format matters when you're using 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 app will render 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.
Additionally, this is an established convention in Rails-land, so it's just a good idea to do this anyway, even if you're not using the auto-responders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With