2013-10-30 52 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的所有相关代码? –