Skip to content

Commit

Permalink
^x
Browse files Browse the repository at this point in the history
^X
merge

Merge branch 'followings-followers'

^X
exit
C
C
vd	wq
:qw
:wq

^X
.q
								c
eiit
exit

y

exit
:wq

:wq
  • Loading branch information
a-saki committed Jul 10, 2016
2 parents d627309 + 8584b4a commit 63ca3a3
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 8 deletions.
57 changes: 57 additions & 0 deletions app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,61 @@ span.picture {
input {
border: 0;
}
}

/* フォロー一覧 */
.person-block {
a:hover {
text-decoration: none;
.panel {
background-color: #e8e8e8;
}
}
}

.other-links {
list-style-type: none;
padding: 0;
display: table;
width: 100%;
.num {
font-size: 18px;
}
a {
display: block;
&:hover {
text-decoration: none;
}
}
span {
display: block;
}
.s-txt {
font-size: 10px;
color: #8899a6;
}
li {
display: table-cell;
}
}

.other-info-lists {
padding: 0;
list-style-type: none;
li {
display: table;
padding: 10px 0;
width: 100%;
border-bottom: 1px solid #e8e8e8;
}
.info-ttl {
vertical-align: center;
display: table-cell;
font-size: 10px;
color: #8899a6;
}
.info-content {
vertical-align: center;
display: table-cell;
}
}
10 changes: 10 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def update
end
end

def followings
@user = User.find(params[:id])
@followings = @user.following_users
end

def followers
@user = User.find(params[:id])
@followings = @user.follower_users
end

private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation, :location, :introduce, :homepage, :birthday)
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def unfollow(other_user)

#フォローしているかどうか
def following?(other_user)
following_relationships.include?(other_user)
following_users.include?(other_user)
end

#自分とフォローしてるユーザのつぶやきを取得
Expand Down
51 changes: 51 additions & 0 deletions app/views/layouts/_aside.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

<section class="user_info">
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
<ul class="other-links">
<li>
<%= link_to user_path(@user) do %>
<span class="s-txt">ツイート</span>
<span class="num"><%= @user.microposts.count %></span>
<% end %>
</li>
<li>
<%= link_to followings_user_path(@user) do %>
<span class="s-txt">フォロー</span>
<span class="num"><%= @user.following_users.count %></span>
<% end %>
</li>
<li>
<%= link_to followers_user_path(@user) do %>
<span class="s-txt">フォロワー</span>
<span class="num"><%= @user.follower_users.count %></span>
<% end %>
</li>
</ul>
<% if @user == current_user %>
<div class="other-info">
<ul class="other-info-lists">
<% unless @user.birthday.blank? %>
<li>
<p class="info-ttl">誕生日</p>
<p class="info-content"><%= @user.birthday.try(:strftime, "%Y年%m月%d日") %></p>
</li>
<% end %>
<% unless @user.location.blank? %>
<li>
<p class="info-ttl">地域</p>
<p class="info-content"><%= @user.location %></p>
</li>
<% end %>
<% unless @user.homepage.blank? %>
<li>
<p class="info-ttl">ホームページ</p>
<p class="info-content"><%= @user.homepage %></p>
</li>
<% end %>
</ul>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/users/_followlists.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="person-block col-md-4">
<%= link_to user_path(object), class: "person-link" do %>
<div class="panel panel-default">
<div class="panel-body">
<p><%= gravatar_for object %></p>
<p class="name"><%= object.name %></p>
</div>
</div><!--/panel-->
<% end %>
</div><!--/person-block-->
14 changes: 14 additions & 0 deletions app/views/users/followers.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<aside class="col-md-4">
<%= render "layouts/aside" %>
</aside>
<div class="col-md-8">
<h2 class="text-left">フォロワ一覧</h2>
<div class="wrp-block row">
<% @followings.each do |following| %>
<%= render "followlists", object: following %>
<% end %>
</div>
</div>
</div>
13 changes: 13 additions & 0 deletions app/views/users/followings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="row">
<aside class="col-md-4">
<%= render "layouts/aside" %>
</aside>
<div class="col-md-8">
<h2 class="text-left">フォローしてる人一覧</h2>
<div class="wrp-block row">
<% @followings.each do |following| %>
<%= render "followlists", object: following %>
<% end %>
</div>
</div>
</div>
12 changes: 5 additions & 7 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@


<div class="row">
<aside class="col-md-4">
<section class="user_info">
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
<%= render "layouts/aside" %>

</aside>
<div class="col-md-8">
<%= render 'follow_form' if logged_in? %>
<% if @user.microposts.any? %>
<h3>Microposts (<%= @user.microposts.count %>)</h3>
<h3>投稿 (<%= @user.microposts.count %>)</h3>
<ol class="microposts">
<%= render @microposts %>
</ol>
Expand Down
7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
resources :sessions, only: [:new, :create, :destroy]
resources :microposts
resources :relationships, only: [:create, :destroy]

resources :users do
member do
get 'followings'
get 'followers'
end
end

# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
Expand Down

0 comments on commit 63ca3a3

Please sign in to comment.