From 846d6e646558beebd4614c296877463952b0f170 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 27 Oct 2014 11:06:31 -0400 Subject: [PATCH] Use our relationship appropriately --- Gemfile | 1 + Gemfile.lock | 5 +++++ app/controllers/friendships_controller.rb | 5 ++--- app/views/friendships/index.html.erb | 8 ++++---- config/initializers/bullet.rb | 5 +++++ 5 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 config/initializers/bullet.rb diff --git a/Gemfile b/Gemfile index b70b131..e980654 100644 --- a/Gemfile +++ b/Gemfile @@ -19,3 +19,4 @@ gem 'bootstrap-sass', '~> 3.2.0.2' gem 'rb-readline' gem 'quiet_assets', group: :development +gem "bullet", :group => "development" diff --git a/Gemfile.lock b/Gemfile.lock index 1967c16..963c8cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,6 +31,9 @@ GEM bootstrap-sass (3.2.0.2) sass (~> 3.2) builder (3.2.2) + bullet (4.14.0) + activesupport (>= 3.0.0) + uniform_notifier (>= 1.6.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -131,12 +134,14 @@ GEM uglifier (2.5.3) execjs (>= 0.3.0) json (>= 1.8.0) + uniform_notifier (1.6.2) PLATFORMS ruby DEPENDENCIES bootstrap-sass (~> 3.2.0.2) + bullet coffee-rails (~> 4.0.0) jbuilder (~> 2.0) jquery-rails diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb index 673ae10..7aa233e 100644 --- a/app/controllers/friendships_controller.rb +++ b/app/controllers/friendships_controller.rb @@ -2,7 +2,7 @@ class FriendshipsController < ApplicationController before_action :require_login def index - @friends = current_user.friends + @friendships = Friendship.includes(:friend).where(user_id: current_user.id) end def create @@ -18,8 +18,7 @@ class FriendshipsController < ApplicationController end def destroy - @friendship = Friendship.where(user_id: current_user.id, - friend_id: params[:id]).take + @friendship = Friendship.find(params[:id]) @friendship.destroy flash[:success] = 'Friend has been removed from your friends' diff --git a/app/views/friendships/index.html.erb b/app/views/friendships/index.html.erb index fbc69aa..e00e320 100644 --- a/app/views/friendships/index.html.erb +++ b/app/views/friendships/index.html.erb @@ -8,11 +8,11 @@ - <% @friends.each do |friend| %> + <% @friendships.each do |friendship| %> - <%= friend.name %> - <%= link_to 'Destroy', friendship_path(friend), method: :delete, - data: { confirm: 'Are you sure?' } %> + <%= friendship.friend.name %> + [ <%= link_to 'Destroy', friendship, method: :delete, + data: { confirm: 'Are you sure?' } %> ] <% end %> diff --git a/config/initializers/bullet.rb b/config/initializers/bullet.rb new file mode 100644 index 0000000..7ca6f04 --- /dev/null +++ b/config/initializers/bullet.rb @@ -0,0 +1,5 @@ +if defined? Bullet + Bullet.enable = true + #Bullet.alert = true + Bullet.bullet_logger = true +end