Javascript Include Tag Best Practice in a Rails Application

后端 未结 4 2224
死守一世寂寞
死守一世寂寞 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:48

    I would use content_for.

    For instance, specify the place to insert it in the application layout:

    
    Merry Christmas!
    <%= yield(:head) -%>
    
    

    And send it there from a view:

    <%- content_for(:head) do -%>
    <%= javascript_include_tag :defaults -%>
    <%- end -%>
    

提交回复
热议问题