Skip to content

Commit

Permalink
delete favorite fix, WIP: delete fave from skill card
Browse files Browse the repository at this point in the history
  • Loading branch information
acmei committed Dec 23, 2015
1 parent 9d6b42a commit 2b81110
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
28 changes: 20 additions & 8 deletions app/assets/javascripts/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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')
});
}
});
});

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/skills_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2b81110

Please sign in to comment.