From 1b15add6b1a44ae0afb0b6205e830fc604501f68 Mon Sep 17 00:00:00 2001 From: nilsding Date: Sun, 30 Nov 2014 15:13:37 +0100 Subject: [PATCH] added ajax controller thing --- app/controllers/ajax/friend_controller.rb | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/controllers/ajax/friend_controller.rb b/app/controllers/ajax/friend_controller.rb index a632a9d4..c6e50fef 100644 --- a/app/controllers/ajax/friend_controller.rb +++ b/app/controllers/ajax/friend_controller.rb @@ -1,11 +1,37 @@ class Ajax::FriendController < ApplicationController def create + params.require :screen_name + + target_user = User.find_by_screen_name(params[:screen_name]) + + begin + current_user.follow target_user + rescue + @status = :fail + @message = "You are already following that user." + @success = false + return + end + @status = :okay @message = "Successfully followed user." @success = true end def destroy + params.require :screen_name + + target_user = User.find_by_screen_name(params[:screen_name]) + + begin + current_user.unfollow target_user + rescue + @status = :fail + @message = "You are not following that user." + @success = false + return + end + @status = :okay @message = "Successfully unfollowed user." @success = true