Skip to content

Commit 562f6aa

Browse files
abhiraosteveklabnik
authored andcommitted
Updating user controller to use following policy
1 parent 5c5276b commit 562f6aa

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

app/controllers/users_controller.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ class UsersController < InheritedController
44

55
def follow
66
followee = User.first(:id => params[:user][:followee])
7-
if current_user == followee
8-
redirect_to resource_path(followee), :notice=> "You can't follow yourself silly!"
9-
return
7+
policy = FollowingPolicy.new(current_user, followee)
8+
if policy.can_follow?
9+
current_user.follow! followee
10+
notice = "You're following #{followee.username} now"
11+
elsif policy.following_self?
12+
notice = "You can't follow yourself silly!"
13+
elsif policy.already_following?
14+
notice = "You're already following #{followee.username}"
1015
end
11-
current_user.follow! followee
12-
redirect_to resource_path(followee), :notice=> "You're following #{followee.username} now"
16+
redirect_to resource_path(followee), :notice=> notice
1317
end
1418

1519
def unfollow

0 commit comments

Comments
 (0)