File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 #render the template
1010 haml :"hackers/show"
1111end
12+
13+ #this lets you follow a Hacker
14+ get '/hackers/:name/follow' do
15+ #we have to be logged in to follow someone
16+ require_login! :return => "/hackers/#{ params [ :name ] } /follow"
17+
18+ #find the hacker with the given name
19+ @hacker = Hacker . first ( :username => params [ :name ] )
20+
21+ #follow them!
22+ Hacker . push_uniq ( current_user . id , :following => @hacker . email )
23+ Hacker . push_uniq ( @hacker . id , :followers => current_user . email )
24+
25+ #set a message
26+ flash [ :notice ] = "Now following #{ params [ :name ] } ."
27+
28+ #redirect back to your page!
29+ redirect "/hackers/#{ current_user . username } "
30+
31+ end
Original file line number Diff line number Diff line change @@ -30,3 +30,13 @@ Feature: Hacker management
3030 When I follow "Your Page"
3131 Then I should be on the hacker page for "steve"
3232 And I should not see "Send steve a message"
33+ Scenario : Following Hackers
34+ Given there's a hacker with the username "fela"
35+ And I'm logged in as "steve"
36+ When I go to the hacker page for "fela"
37+ And I follow "Follow fela"
38+ Then I should see "Now following fela."
39+ And I should be on the hacker page for "steve"
40+ And I should see "Following: 1"
41+ And I go to the hacker page for "fela"
42+ And I should see "Followers: 1"
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ class Hacker
1616 #this is a flag to let us know if this Hacker can administrate the site or not.
1717 key :admin , Boolean , :default => false
1818
19+ #the list of emails this user is following
20+ key :following , Array
21+
22+ #the list of emails of users that are following this user
23+ key :followers , Array
24+
1925 #we don't want to store the password (or the confirmation), so we just make an accessor
2026 attr_accessor :password , :password_confirmation
2127
Original file line number Diff line number Diff line change 11%p = @hacker.username + " 's page"
22%p
3- %img {:src => @hacker.gravatar_url}
3+ %img {:src => @hacker.gravatar_url}
4+ %p Following: #{@hacker.following.count}
5+ %p Followers: #{@hacker.followers.count}
46
57- if logged_in? && @hacker.username != current_user.username
6- %a{:href => " /messages/new/to/#{ @hacker .username} " }= " Send #{ @hacker .username} a message"
8+ %a {:href => " /messages/new/to/#{ @hacker .username} " }= " Send #{ @hacker .username} a message"
9+ %a{:href => " /hackers/#{ @hacker .username} /follow" } Follow #{@hacker.username}
You can’t perform that action at this time.
0 commit comments