2
votes

I'm not sure I understand the difference between html.erb or haml.erb files and .erb files in the views for a Ruby on Rails application.

What are the dis/advantages of each (html.erb/haml.erb or .erb/.haml) files?

PS I'm not asking about the difference between the erb and haml files -- just appending the extension to an html file versus not appending it.

1
Soo, the post says that it depends on what the action "responds to". I'm not sure what that means... Clarification? Also, it doesn't explain html.erb vs just the .erb extension really... - user5243421
The post basically says that it is up to you how you will name the file, only the "erb" extension is needed. However, Ruby on Rails application can respond for requests different than html only. Take for example AJAX - this sends request in javascript. There are also other types, for example if you would like to create a web service (SOA), you would have to answer to xml requests with xml. You can also serve JSON, e.g. as a part of some API. - Gabriel Ščerbák
Now imagine you have an action (controller method) which can respond with different types. Which view template to use is than determined with second extension as in "html.erb" or "js.erb". - Gabriel Ščerbák

1 Answers

0
votes

Mainly this is about content-type and if you have any respond_to blocks in your controller. If you declare your file with a .html.erb or .haml.erb extension you are reducing the scope of response that those files can be used, which will only be served if the request is for the mime type. When using only .erbyou expand the usability of your file, not restricting it's response type.