1
0
Fork 0
find-us-lunch/app/controllers/friendships_controller.rb
2014-10-24 11:26:44 -04:00

35 lines
779 B
Ruby

class FriendshipsController < ApplicationController
before_action :require_login
def index
@friends = current_user.friends
end
def create
@friendship = current_user.friendships.build(friendship_params)
if @friendship.save
flash[:notice] = 'Added friend.'
redirect_to root_url
else
flash[:notice] = 'Unable to add friend.'
redirect_to root_url
end
end
def destroy
@friendship = Friendship.where(user_id: current_user.id,
friend_id: params[:id]).take
@friendship.destroy
flash[:success] = 'Friend has been removed from your friends'
redirect_to friendships_path
end
private
def friendship_params
# why not namespaced
params.permit(:friend_id)
end
end