Use our relationship appropriately
This commit is contained in:
parent
73cc9c24df
commit
846d6e6465
5 changed files with 17 additions and 7 deletions
1
Gemfile
1
Gemfile
|
@ -19,3 +19,4 @@ gem 'bootstrap-sass', '~> 3.2.0.2'
|
|||
gem 'rb-readline'
|
||||
|
||||
gem 'quiet_assets', group: :development
|
||||
gem "bullet", :group => "development"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @friends.each do |friend| %>
|
||||
<% @friendships.each do |friendship| %>
|
||||
<tr>
|
||||
<td><%= friend.name %></td>
|
||||
<td><%= link_to 'Destroy', friendship_path(friend), method: :delete,
|
||||
data: { confirm: 'Are you sure?' } %></td>
|
||||
<td><%= friendship.friend.name %></td>
|
||||
<td>[ <%= link_to 'Destroy', friendship, method: :delete,
|
||||
data: { confirm: 'Are you sure?' } %> ]</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
5
config/initializers/bullet.rb
Normal file
5
config/initializers/bullet.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
if defined? Bullet
|
||||
Bullet.enable = true
|
||||
#Bullet.alert = true
|
||||
Bullet.bullet_logger = true
|
||||
end
|
Loading…
Reference in a new issue