erb in coffee script with rails 3.1

前端 未结 5 949
野性不改
野性不改 2020-12-04 15:51

I would like to use some erb in my .coffee files, like the following example

myLatlng: new google.maps.LatLng(<%=@location.latitude %>, &l         


        
5条回答
  •  渐次进展
    2020-12-04 16:25

    I agree with Ciro Centelli to leave the asset pipeline alone, especially if you are using Heroku. No doubt gon is useful if you need to many assignments, but you can also do this without a gem. In your html include

    <%= javascript_tag do %>
        window.latitude = <%=@location.latitude %>
        window.longitdue = <%= @location.longitude %>
    <% end %>
    

    and in your coffee file

    myLatlng: new google.maps.LatLng(window.latitude, window.longitude)
    

    You can often work around other needs in a similar fashion. For instance if you do not want the coffee script to trigger on an element with particular id, then in the html use erb to only add that id when you want it triggered.

提交回复
热议问题