【发布时间】:2014-08-08 20:17:24
【问题描述】:
我很难诊断以下问题。我有一些服务器端跟踪代码,所以当单击下载链接时,我们将 json 请求传递给控制器。这会触发服务器端跟踪调用。
以下代码在 Chrome 中的 Heroku 上运行良好。然而,当我们投入生产(mt)时,我们开始出现一些奇怪的行为。如果您在 Chrome 中单击一次下载,则不会进行跟踪。如果您单击两次,它会跟踪第二次单击。如果您使用 IE11,它会按预期工作,生成跟踪事件。如果您使用 Firefox,它永远无法用于生产或暂存。
我们玩了很多东西都没有结果。请帮忙。
Rails 3.2.19 和 Ruby 2.1.0
事物控制器
def show
authorize! :view, @thing, :message => "You do not have access to this thing. Is your subscription current?"
respond_to do |format|
format.html { track_event(current_user, "Viewed thing", {name: @thing.name}) }
format.json do
track_event(current_user, "Downloaded thing", {name: @thing.name})
render json: { :success => "success" }
end
end
end
事物展示视图
<div class="thing_label" data-container="<%= thing.name.parameterize %>-thing">
<% if !thing.zip_file.blank? %>
<%= link_to (image_tag "cloud.png", height:'30', width:'30', :style => "vertical-align:top"), thing.zip_file, class: 'js-download-thing', title: "Download Thing", rel:"tooltip", data: {toggle:"tooltip", placement:"top", title:"Download Thing", thing_id: thing.id} %>
<% end %>
<%= thing.name.upcase %>
</div>
应用布局
</div>
</main>
<%= render 'layouts/tracking' %>
</body>
</html>
部分跟踪
<script> $(function(){ $('.js-download-thing').click(function(){
thing_id = $(this).data("thing-id")
url = "<%= things_path %>/" + thing_id + ".json";
$.get(url); }) }) </script>
【问题讨论】:
-
PS - 我在不同的对象上使用几乎完全相同的模式,它工作正常。该对象的不同之处在于 Rails 服务器将下载的对象发送给用户,而不是将它们定向到外部链接。
标签: javascript ruby-on-rails ruby json ruby-on-rails-3