File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments