From 9cc40af69c421cfe249a0a81e74f19e604a1dd10 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Mon, 8 Feb 2016 02:08:59 +0100 Subject: [PATCH] Fix 500 for mobile like without javascript --- app/assets/javascripts/mobile/mobile.js | 10 +++++----- app/helpers/mobile_helper.rb | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index cc8d84a59..286e1b3e7 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -63,18 +63,18 @@ $(document).ready(function(){ evt.preventDefault(); var link = $(this), likeCounter = $(this).closest(".stream_element").find(".like-count"), - href = link.attr("href"); + url = link.data("url"); if(!link.hasClass("loading")){ if(link.hasClass('inactive')) { $.ajax({ - url: href, + url: url, dataType: 'json', type: 'POST', beforeSend: showLoader(link), success: function(data){ removeLoader(link); - link.attr("href", href + "/" + data["id"]); + link.data("url", url + "/" + data.id); if(likeCounter){ likeCounter.text(parseInt(likeCounter.text(), 10) + 1); @@ -84,13 +84,13 @@ $(document).ready(function(){ } else if(link.hasClass("active")){ $.ajax({ - url: link.attr("href"), + url: url, dataType: 'json', type: 'DELETE', beforeSend: showLoader(link), complete: function(){ removeLoader(link); - link.attr("href", href.replace(/\/\d+$/, '')); + link.data("url", url.replace(/\/\d+$/, "")); if(likeCounter){ likeCounter.text(parseInt(likeCounter.text(), 10) - 1); diff --git a/app/helpers/mobile_helper.rb b/app/helpers/mobile_helper.rb index eb3e26a98..23cc959fb 100644 --- a/app/helpers/mobile_helper.rb +++ b/app/helpers/mobile_helper.rb @@ -20,9 +20,15 @@ module MobileHelper def mobile_like_icon(post) if current_user && current_user.liked?(post) - link_to "", post_like_path(post.id, current_user.like_for(post).id), class: "entypo-heart like-action active" + link_to "", + "#", + data: {url: post_like_path(post.id, current_user.like_for(post).id)}, + class: "entypo-heart like-action active" else - link_to "", post_likes_path(post.id), class: "entypo-heart like-action inactive" + link_to "", + "#", + data: {url: post_likes_path(post.id)}, + class: "entypo-heart like-action inactive" end end