diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 9451955..b875149 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -43,6 +43,7 @@ $(document).ready(function($) { greyBox.css('height', height); greyBox.addClass('display'); + // Colorize stars if (is_favorite) { $('.favorite i').removeClass(); $('.favorite i').addClass('fa fa-star'); @@ -59,14 +60,25 @@ $(document).ready(function($) { var skill_id = that.data('skill_id'); - $.ajax({ - url: "/favorite", - method: "POST", - data: { skill: { id: skill_id } } - }).done(function(data) { - $('.favorite i').removeClass('fa fa-star-o') - $('.favorite i').addClass('fa fa-star') - }); + if (is_favorite) { + $.ajax({ + url: "/favorite", + method: "DELETE", + data: { format: skill_id } + }).done(function(data) { + $('.favorite i').removeClass(); + $('.favorite i').addClass('fa fa-star-o'); + }); + } else { + $.ajax({ + url: "/favorite", + method: "POST", + data: { skill: { id: skill_id } } + }).done(function(data) { + $('.favorite i').removeClass(); + $('.favorite i').addClass('fa fa-star') + }); + } }); }); diff --git a/app/controllers/skills_controller.rb b/app/controllers/skills_controller.rb index 5e2485b..d899287 100644 --- a/app/controllers/skills_controller.rb +++ b/app/controllers/skills_controller.rb @@ -24,7 +24,8 @@ def favorite def destroy_favorite skill_id = params[:format] - @user.skills.find_by(id: skill_id).destroy + skill = @user.skills.find_by(id: skill_id) + @user.skills.delete(skill) @user.save redirect_to favorites_path diff --git a/db/schema.rb b/db/schema.rb index bc87434..c1a68ac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -17,7 +17,7 @@ enable_extension "plpgsql" create_table "answers", force: :cascade do |t| - t.datetime "date", default: '2015-10-28 04:08:11' + t.datetime "date", default: '2015-12-23 04:57:03' t.integer "num" t.string "text" t.boolean "bool"