1
0
Fork 0
find-us-lunch/app/controllers/friendships_controller.rb

36 lines
735 B
Ruby
Raw Normal View History

2014-10-15 13:32:35 -04:00
class FriendshipsController < ApplicationController
2014-10-15 13:50:58 -04:00
before_action :require_login
2014-10-15 13:32:35 -04:00
def index
2014-10-15 17:00:22 -04:00
@friends = current_user.friends
2014-10-15 13:32:35 -04:00
@friendships = Friendship.all
end
def create
2014-10-15 16:40:46 -04:00
@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
2014-10-15 13:32:35 -04:00
end
end
def destroy
2014-10-15 16:46:36 -04:00
@friendship = Friendship.find(params[:id])
@friendship.destroy
flash[:success] = 'Friend has been removed from your friends'
redirect_to friendships_path
2014-10-15 13:32:35 -04:00
end
private
2014-10-15 16:40:46 -04:00
def friendship_params
# why not namespaced
params.permit(:friend_id)
end
2014-10-15 13:32:35 -04:00
end