|
3 | 3 |
|
4 | 4 | # An individual Hacker's page |
5 | 5 | get '/hackers/:name' do |
6 | | - #find the hacker with the given name |
7 | | - @hacker = Hacker.first(:username => params[:name]) |
| 6 | + #find the hacker with the given name |
| 7 | + @hacker = Hacker.first(:username => params[:name]) |
8 | 8 |
|
9 | | - #render the template |
10 | | - haml :"hackers/show" |
| 9 | + #render the template |
| 10 | + haml :"hackers/show" |
11 | 11 | end |
12 | 12 |
|
13 | 13 | #update a hacker's information |
14 | 14 | post '/hackers/update' do |
15 | | - #you have to be logged in to update your info |
16 | | - require_login! :return => "/hackers/update" |
17 | | - |
18 | | - #do they want to update their password |
19 | | - unless params[:password].nil? |
20 | | - if params[:password][:new] == params[:password][:confirm] |
21 | | - current_user.password = params[:password][:new] |
22 | | - current_user.save |
23 | | - flash[:notice] = "Password updated!" |
24 | | - else |
25 | | - flash[:notice] = "Password confirmation didn't match!" |
26 | | - end |
27 | | - else |
28 | | - current_user.update_attributes(:about => params[:hacker][:about]) |
29 | | - current_user.save |
30 | | - flash[:notice] = "About information updated!" |
31 | | - end |
32 | | - |
33 | | - redirect "/hackers/#{current_user.username}" |
34 | | - |
| 15 | + #you have to be logged in to update your info |
| 16 | + require_login! :return => "/hackers/update" |
| 17 | + |
| 18 | + #do they want to update their password |
| 19 | + unless params[:password].nil? |
| 20 | + if params[:password][:new] == params[:password][:confirm] |
| 21 | + current_user.password = params[:password][:new] |
| 22 | + current_user.save |
| 23 | + flash[:notice] = "Password updated!" |
| 24 | + else |
| 25 | + flash[:notice] = "Password confirmation didn't match!" |
| 26 | + end |
| 27 | + else |
| 28 | + current_user.update_attributes(:about => params[:hacker][:about]) |
| 29 | + current_user.save |
| 30 | + flash[:notice] = "About information updated!" |
| 31 | + end |
| 32 | + |
| 33 | + redirect "/hackers/#{current_user.username}" |
| 34 | + |
35 | 35 | end |
36 | 36 |
|
37 | 37 | #this lets you follow a Hacker |
38 | 38 | get '/hackers/:name/follow' do |
39 | | - #we have to be logged in to follow someone |
40 | | - require_login! :return => "/hackers/#{params[:name]}/follow" |
| 39 | + #we have to be logged in to follow someone |
| 40 | + require_login! :return => "/hackers/#{params[:name]}/follow" |
41 | 41 |
|
42 | | - #find the hacker with the given name |
43 | | - @hacker = Hacker.first(:username => params[:name]) |
| 42 | + #find the hacker with the given name |
| 43 | + @hacker = Hacker.first(:username => params[:name]) |
44 | 44 |
|
45 | | - #make sure we're not following them already |
46 | | - if current_user.following? @hacker |
47 | | - flash[:notice] = "You're already following #{params[:name]}." |
48 | | - redirect "/hackers/#{current_user.username}" |
49 | | - return |
50 | | - end |
| 45 | + #make sure we're not following them already |
| 46 | + if current_user.following? @hacker |
| 47 | + flash[:notice] = "You're already following #{params[:name]}." |
| 48 | + redirect "/hackers/#{current_user.username}" |
| 49 | + return |
| 50 | + end |
51 | 51 |
|
52 | | - #follow them! |
53 | | - current_user.follow! @hacker |
| 52 | + #follow them! |
| 53 | + current_user.follow! @hacker |
54 | 54 |
|
55 | | - #set a message |
56 | | - flash[:notice] = "Now following #{params[:name]}." |
| 55 | + #set a message |
| 56 | + flash[:notice] = "Now following #{params[:name]}." |
57 | 57 |
|
58 | | - #redirect back to your page! |
59 | | - redirect "/hackers/#{current_user.username}" |
| 58 | + #redirect back to your page! |
| 59 | + redirect "/hackers/#{current_user.username}" |
60 | 60 |
|
61 | 61 | end |
62 | 62 |
|
63 | 63 | #this lets you unfollow a Hacker |
64 | 64 | get '/hackers/:name/unfollow' do |
65 | | - #we have to be logged in to unfollow someone |
66 | | - require_login! :return => "/hackers/#{params[:name]}/unfollow" |
| 65 | + #we have to be logged in to unfollow someone |
| 66 | + require_login! :return => "/hackers/#{params[:name]}/unfollow" |
67 | 67 |
|
68 | | - #find the hacker with the given name |
69 | | - @hacker = Hacker.first(:username => params[:name]) |
70 | | - |
71 | | - #make sure we're not following them already |
72 | | - unless current_user.following? @hacker |
73 | | - flash[:notice] = "You're already not following #{params[:name]}." |
74 | | - redirect "/hackers/#{current_user.username}" |
75 | | - return |
76 | | - end |
| 68 | + #find the hacker with the given name |
| 69 | + @hacker = Hacker.first(:username => params[:name]) |
| 70 | + |
| 71 | + #make sure we're not following them already |
| 72 | + unless current_user.following? @hacker |
| 73 | + flash[:notice] = "You're already not following #{params[:name]}." |
| 74 | + redirect "/hackers/#{current_user.username}" |
| 75 | + return |
| 76 | + end |
77 | 77 |
|
78 | | - #unfollow them! |
79 | | - current_user.unfollow! @hacker |
| 78 | + #unfollow them! |
| 79 | + current_user.unfollow! @hacker |
80 | 80 |
|
81 | | - #set a message |
82 | | - flash[:notice] = "No longer following #{params[:name]}." |
| 81 | + #set a message |
| 82 | + flash[:notice] = "No longer following #{params[:name]}." |
83 | 83 |
|
84 | | - #redirect back to your page! |
85 | | - redirect "/hackers/#{current_user.username}" |
| 84 | + #redirect back to your page! |
| 85 | + redirect "/hackers/#{current_user.username}" |
86 | 86 |
|
87 | 87 | end |
88 | 88 |
|
89 | 89 | #this lets us see followers |
90 | 90 | get '/hackers/:name/followers' do |
91 | | - #find the hacker with the given name |
92 | | - @hacker = Hacker.first(:username => params[:name]) |
| 91 | + #find the hacker with the given name |
| 92 | + @hacker = Hacker.first(:username => params[:name]) |
93 | 93 |
|
94 | | - #render our page |
95 | | - haml :"hackers/followers" |
| 94 | + #render our page |
| 95 | + haml :"hackers/followers" |
96 | 96 | end |
97 | 97 |
|
98 | 98 | #this lets us see following |
99 | 99 | get '/hackers/:name/following' do |
100 | | - #find the hacker with the given name |
101 | | - @hacker = Hacker.first(:username => params[:name]) |
| 100 | + #find the hacker with the given name |
| 101 | + @hacker = Hacker.first(:username => params[:name]) |
102 | 102 |
|
103 | | - #render our page |
104 | | - haml :"hackers/following" |
| 103 | + #render our page |
| 104 | + haml :"hackers/following" |
105 | 105 | end |
0 commit comments