From a36fd9f2725d67365625acead3dc63032d672dca Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Thu, 28 Apr 2016 19:37:00 -0700 Subject: [PATCH 01/12] added shescoding_likes to document.cookie --- app/assets/javascripts/resources.js | 50 ++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 6e95670..4b7721b 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -29,10 +29,57 @@ function scrollToTop(event) { $('html, body').animate({scrollTop: 0}, 'slow'); } + +function getCookie(cname) { + var name = cname + "="; + var ca = document.cookie.split(';'); + for(var i = 0; i Date: Thu, 28 Apr 2016 19:43:29 -0700 Subject: [PATCH 02/12] comments updated --- app/assets/javascripts/resources.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 4b7721b..8a107d5 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -61,7 +61,7 @@ function incrementLike(event, target) { var resourceID = target.parentNode.parentNode.action.split('/')[4] console.log(resourceID); - //no shescoding cookie object exists + //create shescoding_likes cookie if it does not exist if (getCookie("_shescoding_likes") === "") { document.cookie = "_shescoding_likes = {}"; @@ -71,13 +71,12 @@ function incrementLike(event, target) { setCookie("_shescoding_likes", newValue, 365); - // else - - //shescoding cookie object exists - - + + //if shescoding cookie object exists //check for resourceID key - //add shescoding resourceID and + //if key exists, do nothing + //else + //add shescoding resourceID and update database var counterEl = form.find('span')[0]; From 75fe78af49c9ca2a1167b4acb2408e49367d23ba Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Fri, 29 Apr 2016 20:28:54 -0700 Subject: [PATCH 03/12] ability to add multiple key value pairs to shescoding cookie --- app/assets/javascripts/resources.js | 36 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 8a107d5..3ec12b5 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -29,7 +29,6 @@ function scrollToTop(event) { $('html, body').animate({scrollTop: 0}, 'slow'); } - function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); @@ -45,7 +44,6 @@ function getCookie(cname) { return ""; } - function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); @@ -53,31 +51,35 @@ function setCookie(cname, cvalue, exdays) { document.cookie = cname + "=" + cvalue + "; " + expires; } - function incrementLike(event, target) { event.preventDefault(); var form = $(target).parents('form'); - var resourceID = target.parentNode.parentNode.action.split('/')[4] + resourceID = target.parentNode.parentNode.action.split('/')[4] console.log(resourceID); //create shescoding_likes cookie if it does not exist - if (getCookie("_shescoding_likes") === "") - { + if (getCookie("_shescoding_likes") === ""){ document.cookie = "_shescoding_likes = {}"; + newValue = JSON.stringify({[resourceID]: true}); + setCookie("_shescoding_likes", newValue, 365); } - - newValue = JSON.stringify({[resourceID]: true}); - setCookie("_shescoding_likes", newValue, 365); - - - //if shescoding cookie object exists - //check for resourceID key - //if key exists, do nothing - //else - //add shescoding resourceID and update database - + else { + // if (getCookie("_shescoding_likes") != "") + var oldCookie = getCookie("_shescoding_likes"); + console.log("oldCookie is " + oldCookie); + + + var newCookie = JSON.parse(oldCookie); + newCookie[resourceID] = true; + newValue = JSON.stringify(newCookie); + setCookie("_shescoding_likes", newValue, 365) + //check for resourceID key + //if key exists, do nothing + //else + //add shescoding resourceID and update database + } var counterEl = form.find('span')[0]; var newCount = 1 + parseInt(counterEl.innerText, 10); From 1960c32ebb3b6d415235cfa69634fe7ec5f764d2 Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Wed, 4 May 2016 14:31:57 -0700 Subject: [PATCH 04/12] added processLike function in order to process likes before decrementing or incrementing like --- app/assets/javascripts/resources.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 3ec12b5..5b764f2 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -51,6 +51,11 @@ function setCookie(cname, cvalue, exdays) { document.cookie = cname + "=" + cvalue + "; " + expires; } +function processLike(event, target){ + //if resource id is already liked decrement like + //if resource id is not in the list increment like +} + function incrementLike(event, target) { event.preventDefault(); var form = $(target).parents('form'); @@ -80,7 +85,7 @@ function incrementLike(event, target) { //else //add shescoding resourceID and update database } - + var counterEl = form.find('span')[0]; var newCount = 1 + parseInt(counterEl.innerText, 10); counterEl.innerText = newCount; From 2a368b4de2cba34a8484d226998d3b7f03fbff1a Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Tue, 17 May 2016 11:54:52 -0700 Subject: [PATCH 05/12] added processLike function that sends to incrementLike if resource isn't already liked --- app/assets/javascripts/resources.js | 41 ++++++++++++++--------------- app/views/resources/index.html.erb | 2 +- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 5b764f2..1ead80c 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -52,40 +52,39 @@ function setCookie(cname, cvalue, exdays) { } function processLike(event, target){ - //if resource id is already liked decrement like - //if resource id is not in the list increment like -} - -function incrementLike(event, target) { event.preventDefault(); - var form = $(target).parents('form'); resourceID = target.parentNode.parentNode.action.split('/')[4] console.log(resourceID); - //create shescoding_likes cookie if it does not exist if (getCookie("_shescoding_likes") === ""){ document.cookie = "_shescoding_likes = {}"; newValue = JSON.stringify({[resourceID]: true}); - setCookie("_shescoding_likes", newValue, 365); + setCookie("_shescoding_likes", newValue, 365); + incrementLike(event, target); + } - //if shescoding cookie object exists + //if shescoding_likes cookie does exist else { - // if (getCookie("_shescoding_likes") != "") - var oldCookie = getCookie("_shescoding_likes"); - console.log("oldCookie is " + oldCookie); - + + //check if resource id exists + var oldCookie = getCookie("_shescoding_likes"); + var newCookie = JSON.parse(oldCookie); - var newCookie = JSON.parse(oldCookie); + //if the resourceid is not liked yet + if (!(newCookie.hasOwnProperty(resourceID))){ newCookie[resourceID] = true; newValue = JSON.stringify(newCookie); - setCookie("_shescoding_likes", newValue, 365) - //check for resourceID key - //if key exists, do nothing - //else - //add shescoding resourceID and update database - } - + setCookie("_shescoding_likes", newValue, 365); + incrementLike(event, target); + }; + }; +}; + +function incrementLike(event, target) { + event.preventDefault(); + var form = $(target).parents('form'); + var counterEl = form.find('span')[0]; var newCount = 1 + parseInt(counterEl.innerText, 10); counterEl.innerText = newCount; diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb index f48e6f3..e4eefca 100644 --- a/app/views/resources/index.html.erb +++ b/app/views/resources/index.html.erb @@ -79,7 +79,7 @@ // Ajax Like $(".heart").click(function(e){ - incrementLike(e, this); + processLike(e, this); }); }); From 6b0b3e5574a588081f13536c19b5d7c0497b3bc4 Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Tue, 17 May 2016 12:00:40 -0700 Subject: [PATCH 06/12] removed console logs --- app/assets/javascripts/resources.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 1ead80c..e4548ec 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -53,25 +53,22 @@ function setCookie(cname, cvalue, exdays) { function processLike(event, target){ event.preventDefault(); - resourceID = target.parentNode.parentNode.action.split('/')[4] - console.log(resourceID); + //create shescoding_likes cookie if it does not exist if (getCookie("_shescoding_likes") === ""){ document.cookie = "_shescoding_likes = {}"; newValue = JSON.stringify({[resourceID]: true}); setCookie("_shescoding_likes", newValue, 365); incrementLike(event, target); - } + //if shescoding_likes cookie does exist else { - //check if resource id exists var oldCookie = getCookie("_shescoding_likes"); var newCookie = JSON.parse(oldCookie); - - //if the resourceid is not liked yet + if (!(newCookie.hasOwnProperty(resourceID))){ newCookie[resourceID] = true; newValue = JSON.stringify(newCookie); From 94e617bc756a28f946cac33a58267f9257913f67 Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Fri, 1 Jul 2016 20:29:18 -0700 Subject: [PATCH 07/12] updated indentation. modified resource id so that it doesn't rely on absolute url --- app/assets/javascripts/resources.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index e4548ec..18dcbc8 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -29,6 +29,7 @@ function scrollToTop(event) { $('html, body').animate({scrollTop: 0}, 'slow'); } +//getCookie function taken from http://www.w3schools.com/js/js_cookies.asp function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); @@ -44,6 +45,7 @@ function getCookie(cname) { return ""; } +//setCookie function taken from http://www.w3schools.com/js/js_cookies.asp function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); @@ -53,7 +55,7 @@ function setCookie(cname, cvalue, exdays) { function processLike(event, target){ event.preventDefault(); - resourceID = target.parentNode.parentNode.action.split('/')[4] + resourceID = target.parentNode.parentNode.action.split('/').slice(-2)[0] //create shescoding_likes cookie if it does not exist if (getCookie("_shescoding_likes") === ""){ @@ -65,15 +67,15 @@ function processLike(event, target){ //if shescoding_likes cookie does exist else { - //check if resource id exists - var oldCookie = getCookie("_shescoding_likes"); - var newCookie = JSON.parse(oldCookie); - - if (!(newCookie.hasOwnProperty(resourceID))){ - newCookie[resourceID] = true; - newValue = JSON.stringify(newCookie); - setCookie("_shescoding_likes", newValue, 365); - incrementLike(event, target); + //check if resource id exists + var oldCookie = getCookie("_shescoding_likes"); + var newCookie = JSON.parse(oldCookie); + + if (!(newCookie.hasOwnProperty(resourceID))){ + newCookie[resourceID] = true; + newValue = JSON.stringify(newCookie); + setCookie("_shescoding_likes", newValue, 365); + incrementLike(event, target); }; }; }; From 936135d99e63bc2d8bfe1ad2dd657269252ba73e Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Sat, 30 Jul 2016 22:48:39 -0700 Subject: [PATCH 08/12] likes now only increase or decrease once. cookie is updating accordingly --- app/assets/javascripts/resources.js | 47 ++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 18dcbc8..d0220af 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -69,14 +69,26 @@ function processLike(event, target){ else { //check if resource id exists var oldCookie = getCookie("_shescoding_likes"); + console.log(resourceID) var newCookie = JSON.parse(oldCookie); - + console.log("current cookie", newCookie); + + //if it doesn't exist, then create it and increment the like if (!(newCookie.hasOwnProperty(resourceID))){ newCookie[resourceID] = true; newValue = JSON.stringify(newCookie); + console.log("doesn't exist so i'm adding", newValue) setCookie("_shescoding_likes", newValue, 365); incrementLike(event, target); - }; + } else { + //if it does exist + //remove resource id from cookie + delete newCookie[resourceID]; + newValue = JSON.stringify(newCookie); + console.log("does exist so i'm removing", newValue); + setCookie("_shescoding_likes", newValue, 365); + decrementLike(event, target); + } }; }; @@ -93,8 +105,33 @@ function incrementLike(event, target) { button.addClass('filled-heart'); } - $.ajax(form.attr("action"), { - type: "POST" - }); + // $.ajax(form.attr("action"), { + // type: "POST" + // }); +} + +function decrementLike(event, target){ + console.log("decrementing like!"); + event.preventDefault(); + + var form = $(target).parents('form'); + console.log("form is", form) + + var counterEl = form.find('span')[0]; + var newCount = parseInt(counterEl.innerText, 10) -1; + if (newCount >= 0){ + counterEl.innerText = newCount; + } + + if (newCount === 0) { + var button = form.find('button'); + button.removeClass('filled-heart'); + button.addClass('heart'); + } + + // $.ajax(form.attr("action"), { + // type: "POST" + // }); + } From 5957b98f843571ca8b175d3c475551ffff652f1f Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Sun, 31 Jul 2016 10:12:45 -0700 Subject: [PATCH 09/12] unlike route added. unlike method added to resource controller. --- app/assets/javascripts/resources.js | 23 ++++++++++++++++------- app/controllers/resources_controller.rb | 6 ++++++ config/routes.rb | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index d0220af..473b6e6 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -71,7 +71,7 @@ function processLike(event, target){ var oldCookie = getCookie("_shescoding_likes"); console.log(resourceID) var newCookie = JSON.parse(oldCookie); - console.log("current cookie", newCookie); + // console.log("current cookie", newCookie); //if it doesn't exist, then create it and increment the like if (!(newCookie.hasOwnProperty(resourceID))){ @@ -85,9 +85,9 @@ function processLike(event, target){ //remove resource id from cookie delete newCookie[resourceID]; newValue = JSON.stringify(newCookie); - console.log("does exist so i'm removing", newValue); + // console.log("does exist so i'm removing", newValue); setCookie("_shescoding_likes", newValue, 365); - decrementLike(event, target); + decrementLike(event, target, resourceID); } }; }; @@ -105,12 +105,12 @@ function incrementLike(event, target) { button.addClass('filled-heart'); } - // $.ajax(form.attr("action"), { - // type: "POST" - // }); + $.ajax(form.attr("action"), { + type: "POST" + }); } -function decrementLike(event, target){ +function decrementLike(event, target, resourceID){ console.log("decrementing like!"); event.preventDefault(); @@ -132,6 +132,15 @@ function decrementLike(event, target){ // $.ajax(form.attr("action"), { // type: "POST" // }); + + var unlike = "resources/"; + unlike += resourceID; + unlike += "/unlike"; + // console.log(unlike); + + $.ajax(form.attr("action", unlike), { + type: "POST" + }); } diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index d439db6..aab627f 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -63,6 +63,12 @@ def like redirect_to resources_path end + def unlike + @resource.likes -= 1 + @resource.save + redirect_to resources_path + end + # DELETE /resources/1 # DELETE /resources/1.json def destroy diff --git a/config/routes.rb b/config/routes.rb index 744eb84..7c12f5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,7 @@ resources :resources, only: [:index] get 'resources/tags/:tag', to: 'resources#index', as: :tag post 'resources/:id/like', to: 'resources#like', as: :like + post 'resources/:id/unlike', to: 'resources#unlike', as: :unlike # Static pages get 'about', to: "static_pages#about" From a62eec826542de68e7408048226a4740f7be7013 Mon Sep 17 00:00:00 2001 From: Porsha Robinson Date: Mon, 23 Jul 2018 20:15:01 -0700 Subject: [PATCH 10/12] updated to accomodate unlikes, added resource update functions --- app/assets/javascripts/resources.js | 104 +++++++++--------------- app/controllers/resources_controller.rb | 10 +-- app/views/resources/index.html.erb | 2 +- config/routes.rb | 3 +- 4 files changed, 43 insertions(+), 76 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index 473b6e6..d79900e 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -53,94 +53,68 @@ function setCookie(cname, cvalue, exdays) { document.cookie = cname + "=" + cvalue + "; " + expires; } +function createNewCookie(target, resourceID){ + document.cookie = "_shescoding_likes = {}"; + newValue = JSON.stringify({[resourceID]: true}); + setCookie("_shescoding_likes", newValue, 365); + incrementLikeinDb(target); +} + function processLike(event, target){ event.preventDefault(); resourceID = target.parentNode.parentNode.action.split('/').slice(-2)[0] - - //create shescoding_likes cookie if it does not exist if (getCookie("_shescoding_likes") === ""){ - document.cookie = "_shescoding_likes = {}"; - newValue = JSON.stringify({[resourceID]: true}); - setCookie("_shescoding_likes", newValue, 365); - incrementLike(event, target); + createNewCookie(target, resrouceID); } - - //if shescoding_likes cookie does exist else { - //check if resource id exists - var oldCookie = getCookie("_shescoding_likes"); - console.log(resourceID) - var newCookie = JSON.parse(oldCookie); - // console.log("current cookie", newCookie); - - //if it doesn't exist, then create it and increment the like - if (!(newCookie.hasOwnProperty(resourceID))){ - newCookie[resourceID] = true; - newValue = JSON.stringify(newCookie); - console.log("doesn't exist so i'm adding", newValue) - setCookie("_shescoding_likes", newValue, 365); - incrementLike(event, target); - } else { - //if it does exist - //remove resource id from cookie - delete newCookie[resourceID]; - newValue = JSON.stringify(newCookie); - // console.log("does exist so i'm removing", newValue); - setCookie("_shescoding_likes", newValue, 365); - decrementLike(event, target, resourceID); - } + updateExistingCookie(target, resourceID); }; }; -function incrementLike(event, target) { - event.preventDefault(); - var form = $(target).parents('form'); - - var counterEl = form.find('span')[0]; - var newCount = 1 + parseInt(counterEl.innerText, 10); - counterEl.innerText = newCount; - - if (newCount === 1) { - var button = form.find('button'); - button.addClass('filled-heart'); - } - - $.ajax(form.attr("action"), { +function updateLikeInDb(target, direction) { + updateLikesHtmlNumber(target, direction); + let form = $(target).parents('form'); + let incrementUrl = form.attr("action").substring(0, form.attr("action").length-1) + direction; + $.ajax(incrementUrl, { type: "POST" }); } -function decrementLike(event, target, resourceID){ - console.log("decrementing like!"); - event.preventDefault(); - - var form = $(target).parents('form'); - console.log("form is", form) +function updateExistingCookie(target, resourceID){ + let direction; + var oldCookie = getCookie("_shescoding_likes"); + var newCookie = JSON.parse(oldCookie); + //if resourceId does not exist in the cookie (not liked yet) add it to the cookie and increment the like + if (!(newCookie.hasOwnProperty(resourceID))){ + newCookie[resourceID] = true; + direction = 1; + } else { + //if resource id does exist in the cookie (liked), remove that resource id from cookie + delete newCookie[resourceID]; + direction = -1; + } + newValue = JSON.stringify(newCookie); + setCookie("_shescoding_likes", newValue, 365); + updateLikeInDb(target, direction); +} +function updateLikesHtmlNumber(target, direction){ + let form = $(target).parents('form'); var counterEl = form.find('span')[0]; - var newCount = parseInt(counterEl.innerText, 10) -1; + var button = form.find('button'); + var newCount = parseInt(counterEl.innerText, 10) + direction; + if (newCount >= 0){ counterEl.innerText = newCount; } if (newCount === 0) { - var button = form.find('button'); button.removeClass('filled-heart'); button.addClass('heart'); } - // $.ajax(form.attr("action"), { - // type: "POST" - // }); - - var unlike = "resources/"; - unlike += resourceID; - unlike += "/unlike"; - // console.log(unlike); - - $.ajax(form.attr("action", unlike), { - type: "POST" - }); - + if (newCount === 1) { + button.addClass('filled-heart'); + } } diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index aab627f..fbaa8ce 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -1,6 +1,6 @@ class ResourcesController < ApplicationController - before_action :set_resource, only: [:show, :edit, :update, :like, :destroy] + before_action :set_resource, only: [:show, :edit, :update, :like, :unlike, :destroy] # GET /resources # GET /resources.json @@ -58,13 +58,7 @@ def update end def like - @resource.likes += 1 - @resource.save - redirect_to resources_path - end - - def unlike - @resource.likes -= 1 + @resource.likes += params[:count].to_i @resource.save redirect_to resources_path end diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb index e4eefca..c230940 100644 --- a/app/views/resources/index.html.erb +++ b/app/views/resources/index.html.erb @@ -36,7 +36,7 @@
<%= format_date(resource.date) %>
diff --git a/config/routes.rb b/config/routes.rb index 7c12f5e..3532359 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,8 +5,7 @@ resources :resources, only: [:index] get 'resources/tags/:tag', to: 'resources#index', as: :tag - post 'resources/:id/like', to: 'resources#like', as: :like - post 'resources/:id/unlike', to: 'resources#unlike', as: :unlike + post 'resources/:id/like/:count', to: 'resources#like', as: :like # Static pages get 'about', to: "static_pages#about" From eda5ad3327c26a923f3de3afc56b3b91c04ac6c5 Mon Sep 17 00:00:00 2001 From: Porsha Robinson Date: Mon, 23 Jul 2018 20:16:44 -0700 Subject: [PATCH 11/12] remove unused controller action --- app/controllers/resources_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb index fbaa8ce..89715b3 100644 --- a/app/controllers/resources_controller.rb +++ b/app/controllers/resources_controller.rb @@ -1,6 +1,6 @@ class ResourcesController < ApplicationController - before_action :set_resource, only: [:show, :edit, :update, :like, :unlike, :destroy] + before_action :set_resource, only: [:show, :edit, :update, :like, :destroy] # GET /resources # GET /resources.json From 41da8b07149c42af3925d4c408cc17ba37dd6715 Mon Sep 17 00:00:00 2001 From: probinson2015 Date: Mon, 15 Oct 2018 10:09:12 -0700 Subject: [PATCH 12/12] fix typo and slice parameters. --- app/assets/javascripts/resources.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/resources.js b/app/assets/javascripts/resources.js index d79900e..e2b7f88 100644 --- a/app/assets/javascripts/resources.js +++ b/app/assets/javascripts/resources.js @@ -62,9 +62,9 @@ function createNewCookie(target, resourceID){ function processLike(event, target){ event.preventDefault(); - resourceID = target.parentNode.parentNode.action.split('/').slice(-2)[0] + resourceID = target.parentNode.parentNode.action.split('/').slice(-3)[0] if (getCookie("_shescoding_likes") === ""){ - createNewCookie(target, resrouceID); + createNewCookie(target, resourceID); } else { updateExistingCookie(target, resourceID);