diff --git a/app/cells/user/followed_topics.html.erb b/app/cells/user/followed_topics.html.erb
new file mode 100644
index 0000000..be5d14c
--- /dev/null
+++ b/app/cells/user/followed_topics.html.erb
@@ -0,0 +1,23 @@
+<% if !@followed_topics.blank? %>
+
+
+
+ <% for topic in @followed_topics %>
+ -
+
+ <% if @current_user %>
+
+ <% if @current_user.topic_followed?(topic) %>
+
取消关注
+ <% else %>
+
关注
+ <% end %>
+
+ <% end %>
+
+ <% end %>
+
+
+<% end %>
diff --git a/app/cells/user/followers.html.erb b/app/cells/user/followers.html.erb
new file mode 100644
index 0000000..b71bee7
--- /dev/null
+++ b/app/cells/user/followers.html.erb
@@ -0,0 +1,14 @@
+<% if !@followers.blank? %>
+
+
最近关注<%= user_sex_title(@user) %>的人
+
+
+<% end %>
diff --git a/app/cells/user/following.html.erb b/app/cells/user/following.html.erb
new file mode 100644
index 0000000..b076f21
--- /dev/null
+++ b/app/cells/user/following.html.erb
@@ -0,0 +1,15 @@
+<% if !@following.blank? %>
+
+
<%= user_sex_title(@user) %>最近关注的人
+
+
+<% end %>
+
diff --git a/app/cells/user_cell.rb b/app/cells/user_cell.rb
new file mode 100644
index 0000000..ff6bcc6
--- /dev/null
+++ b/app/cells/user_cell.rb
@@ -0,0 +1,41 @@
+class UserCell < Cell::Rails
+ helper :users
+ cache :followers, :followers_key, :expires_in => 3.days
+ cache :following, :following_key, :expires_in => 3.days
+
+ def followed_topics(opts = {})
+ @user = opts[:user] || nil
+ @current_user = opts[:current_user] || nil
+ if @user
+ @followed_topics = @user.followed_topics.desc("$natural").limit(7)
+ end
+ render
+ end
+
+ def followers(opts = {})
+ @user = opts[:user] || nil
+ if @user
+ @followers = @user.followers.desc("$natural").limit(42)
+ end
+ render
+ end
+
+ def following(opts = {})
+ @user = opts[:user] || nil
+ if @user
+ @following = @user.following.desc("$natural").limit(42)
+ end
+ render
+ end
+
+ private
+ def followers_key(opts = {})
+ return "followers/nil" if opts[:user].blank?
+ "followers/#{opts[:user].id}/#{opts[:user].follower_ids.to_s.md5}"
+ end
+
+ def following_key(opts = {})
+ return "following/nil" if opts[:user].blank?
+ "following/#{opts[:user].id}/#{opts[:user].following_ids.to_s.md5}"
+ end
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index a4ca1de..25ce1b3 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -32,9 +32,6 @@ def user_tagline_tag(user,options = {})
def user_sex_title(user)
return "" if user.blank?
- if current_user
- return "我" if user.id == current_user.id
- end
user.girl.blank? == true ? "他" : "她"
end
diff --git a/app/views/users/_sidebar.html.erb b/app/views/users/_sidebar.html.erb
index ce4ea6c..a853497 100644
--- a/app/views/users/_sidebar.html.erb
+++ b/app/views/users/_sidebar.html.erb
@@ -38,45 +38,9 @@
注册于 <%= l user.created_at.to_date, :format => :long %>
-<% if @user.followed_topic_ids.size > 0 %>
-
-
-
- <% for topic in @user.followed_topics.desc("$natural").limit(7) %>
- <%= render "topic", :topic => topic %>
- <% end %>
-
-
-<% end %>
-
-<% if @user.follower_ids.size > 0 %>
-
-
最近关注<%= user_sex_title(@user) %>的人
-
-
-<% end %>
+<%= render_cell :user, :followed_topics, :user => @user, :current_user => current_user %>
+<%= render_cell :user, :followers, :user => @user %>
+<%= render_cell :user, :following, :user => @user %>
-<% if @user.following_ids.size > 0 %>
-
-
<%= user_sex_title(@user) %>最近关注的人
-
-
-<% end %>
<% end %>