Difference between application.haml and application.html.haml?

Since many days I tried to understand why a simple link like this:

link_to 'My Link', my_path(format: :js), remote: true 

always returned the full HTML document instead of executing the javascript located in file.js.erb:

 alert('hello world') 

[...]

After hours of debugging, I discovered why:

When I rename my main layout file, for example : application.haml , it displays the full HTML document:

 Started GET "/my_path/2.js" for 127.0.0.1 at 2016-03-05 12:28:20 +0100 Processing by MyController#show as JS Rendered my_path/show.js.erb within layouts/application (0.1ms) Rendered layouts/_sidebar.html.erb (18.9ms) Rendered layouts/_headbar.haml (0.5ms) Rendered layouts/_flash_messages.html.haml (0.2ms) Rendered layouts/_footer.html.erb (0.1ms) Completed 200 OK in 102ms (Views: 59.3ms | ActiveRecord: 2.9ms) 

When I rename my main layout file, for example : application.html.haml , it correctly executes javascript and launches a welcome popup:

 Started GET "/my_path/8.js" for 127.0.0.1 at 2016-03-05 12:28:34 +0100 Processing by MyController#show as JS Rendered my_path/show.js.erb (0.1ms) Completed 200 OK in 24ms (Views: 21.8ms | ActiveRecord: 0.4ms) 

Why is there a difference in JavaScript behavior according to the different names of my layout?

+5
source share
1 answer

As BroiSatse said:

This is not JavaScript behavior, as rails look for patterns. First it searches for <action_name>.<templating-engine> files, then for <action_name>.<format><templateing-engine> . So when you have a common template without a format, it will be taken for all formats.

+1
source

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


All Articles