-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial interface for following/followers
- Loading branch information
Showing
10 changed files
with
126 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<% @user ||= current_user %> | ||
<div class="stats"> | ||
<table summary="User stats"> | ||
<tr> | ||
<td> | ||
<a href="<%= following_user_path(@user) %>"> | ||
<span id="following" class="stat"> | ||
<%= @user.following.count %> following | ||
</span> | ||
</a> | ||
</td> | ||
<td> | ||
<a href="<%= followers_user_path(@user) %>"> | ||
<span id="followers" class="stat"> | ||
<%= pluralize(@user.followers.count, "follower") %> | ||
</span> | ||
</a> | ||
</td> | ||
</tr> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= form_for(current_user.relationships. | ||
build(:followed_id => @user.id)) do |f| %> | ||
<div><%= f.hidden_field :followed_id %></div> | ||
<div class="actions"><%= f.submit "Follow" %></div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% unless current_user?(@user) %> | ||
<div id="follow_form"> | ||
<% if current_user.following?(@user) %> | ||
<%= render 'unfollow' %> | ||
<% else %> | ||
<%= render 'follow' %> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= form_for(current_user.relationships.find_by_followed_id(@user), | ||
:html => { :method => :delete }) do |f| %> | ||
<div class="actions"><%= f.submit "Unfollow" %></div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,25 +4,42 @@ namespace :db do | |
desc "Fill database with sample data" | ||
task :populate => :environment do | ||
Rake::Task['db:reset'].invoke | ||
admin = User.create!(:name => "Example User", | ||
:email => "[email protected]", | ||
:password => "foobar", | ||
:password_confirmation => "foobar") | ||
admin.toggle!(:admin) | ||
99.times do |n| | ||
name = Faker::Name.name | ||
email = "example-#{n+1}@railstutorial.org" | ||
password = "password" | ||
User.create!(:name => name, | ||
:email => email, | ||
:password => password, | ||
:password_confirmation => password) | ||
end | ||
|
||
User.all(:limit => 6).each do |user| | ||
50.times do | ||
user.microposts.create!(:content => Faker::Lorem.sentence(5)) | ||
end | ||
make_users | ||
make_microposts | ||
make_relationships | ||
end | ||
end | ||
|
||
def make_users | ||
admin = User.create!(:name => "Example User", | ||
:email => "[email protected]", | ||
:password => "foobar", | ||
:password_confirmation => "foobar") | ||
admin.toggle!(:admin) | ||
99.times do |n| | ||
name = Faker::Name.name | ||
email = "example-#{n+1}@railstutorial.org" | ||
password = "password" | ||
User.create!(:name => name, | ||
:email => email, | ||
:password => password, | ||
:password_confirmation => password) | ||
end | ||
end | ||
|
||
def make_microposts | ||
User.all(:limit => 6).each do |user| | ||
50.times do | ||
user.microposts.create!(:content => Faker::Lorem.sentence(5)) | ||
end | ||
end | ||
end | ||
|
||
def make_relationships | ||
users = User.all | ||
user = users.first | ||
following = users[1..50] | ||
followers = users[3..40] | ||
following.each { |followed| user.follow!(followed) } | ||
followers.each { |follower| follower.follow!(user) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters