Javascript Include Tag Best Practice in a Rails Application

后端 未结 4 2225
死守一世寂寞
死守一世寂寞 2020-12-12 11:50

Say I need to call a javascript file in the of an ERb template. My instinct is to do the usual:


<%= javascript_incl         


        
4条回答
  •  盖世英雄少女心
    2020-12-12 12:28

    I usually have the following in the layout file:

    
      <%= javascript_include_tag :defaults %> 
      <%= @extra_head_content %>
    
    

    And then in the views:

    <% (@extra_head_content ||= "") += capture do %>
      <%= other_content %>
    <% end %>
    

    See the API documentation for #capture

提交回复
热议问题