2013-10-30 51 views
0

我想JS整合addthis(smartlayers)到我的軌道4,5應用添加此集成通過軌道turbolinks

我添加的代碼在兩頁如(節目模板,編輯模板)

,當我瀏覽從一個頁面到另一個頁面使用鏈接我看不到工作圖標

當我刷新頁面時,我能夠看到圖標。我GOOGLE了,我發現在軌道上的頁面使用turbolinks導航。

我試過this的解決方案,但無法解決它。

這裏是我的編輯模板

<h1>Editing product</h1> 

<%= render 'form' %> 

<%= link_to 'Show', @product %> | 
<%= link_to 'Back', products_path %> 
<!-- Go to http://www.addthis.com/get/smart-layers to customize --> 
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5270a69567915956"></script> 
<script type="text/javascript"> 
    addthis.layers(); 
</script> 
<!-- AddThis Smart Layers END --> 
<!-- AddThis Button END --> 

和我的節目模板

<p id="notice"><%= notice %></p> 

<p> 
<%= image_tag @product.photo.url(:medium) %> 
</p> 
<p> 
    <strong>Title:</strong> 
    <%= @product.title %> 
</p> 

<p> 
    <strong>Sku:</strong> 
    <%= @product.sku %> 
</p> 

<p> 
    <strong>Description:</strong> 
    <%= @product.description %> 
</p> 

<p> 
    <strong>Price:</strong> 
    <%= @product.price %> 
</p> 


<%= button_to 'Add to cart', line_items_path(:product_id => @product), :class =>"btn btn-success" %> 
<%= link_to 'Edit', edit_product_path(@product) %> | 
<%= link_to 'Back', products_path %> 

<!-- AddThis Smart Layers BEGIN --> 
<!-- Go to http://www.addthis.com/get/smart-layers to customize --> 
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5270a69567915956"></script> 
<script type="text/javascript"> 
    addthis.layers(); 
</script> 
<!-- AddThis Smart Layers END --> 

回答

0

我也有這個問題,那是因爲Turbolinks沒有完全重新加載頁面,它只是抓住了身體,所以你是JS或CoffeeScript不會加載到新頁面上。

要解決:

ready = ->在你的CoffeeScript文件的頂部,並把$(document).ready(ready) $(document).on('page:load', ready)在文件的結尾。

像這樣:

ready = -> 
. 
. 
. 
$(document).ready(ready) 
$(document).on('page:load', ready) 

你可以閱讀有關的Turbolinks GitHub的代碼。

+0

感謝您的回覆,我對其他人使用了相同的策略(例如:google analytics),但它不適用於addthis smartlayers –

+1

您是否可以編輯您的問題以包含AddThis的所有相關代碼? –