Skip to content

Commit

Permalink
added delete favorite
Browse files Browse the repository at this point in the history
  • Loading branch information
acmei committed Oct 30, 2015
1 parent 91eead3 commit c6d87a5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/skills.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ p.card-title {
}

/* FAVORITE */

.favorite-delete {
float: right;
}
8 changes: 8 additions & 0 deletions app/controllers/skills_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def favorite
render nothing: true
end

def destroy_favorite
skill_id = params[:format]
@user.skills.find_by(id: skill_id).destroy
@user.save

redirect_to favorites_path
end

private

def skill_params
Expand Down
5 changes: 2 additions & 3 deletions app/views/users/_favorite.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<div class="panel panel-default">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<%= number %>" aria-expanded="false" aria-controls="collapse<%= number %>">
<div class="panel-heading" role="tab" id="heading<%= number %>">
<div class="panel-heading" role="tab" id="heading<%= number %>" data-toggle="collapse" data-parent="#accordion" href="#collapse<%= number %>" aria-expanded="false" aria-controls="collapse<%= number %>">
<%= link_to "\u00D7", favorite_path(id), class: 'favorite-delete', method: :delete, data: { confirm: "Delete this favorite?" } %>
<h4 class="panel-title">
<%= fa_icon 'star' %><%= title %>
</h4>
</div>
</a>
<div id="collapse<%= number %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading<%= number %>">
<div class="panel-body">
<%= desc %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/users/favorites.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<%= render partial: 'favorite', locals: {
number: favorite.id,
title: favorite.text.titlecase,
desc: favorite.description
desc: favorite.description,
id: favorite.id
} %>
<% end %>
</div>
Expand Down
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
delete "logout" => "sessions#destroy"

# Favorite
get "favorites" => "users#favorites"
post "favorite" => "skills#favorite"
get "favorites" => "users#favorites"
post "favorite" => "skills#favorite"
delete "favorite" => "skills#destroy_favorite"

# Account Activation
resources :account_activations, only: [:edit]
Expand Down

0 comments on commit c6d87a5

Please sign in to comment.