Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update comments_count

  • Loading branch information...
commit 6d59b57296eaede3e07c2a78b10a0d7c683bf428 1 parent d903d7f
@sjoonk authored
View
1  app/controllers/comments_controller.rb
@@ -4,6 +4,7 @@ def create
# raise params[:entry_id].inspect
@entry = Entry.find(params[:entry_id])
@comment = Comment.new(params[:comment])
+ @comment.user = current_user
@entry.comments << @comment
@entry.save
respond_to do |format|
View
6 app/models/comment.rb
@@ -13,11 +13,13 @@ class Comment
protected
def increment_count
- self.user.comments_count += 1
+ # self.user.update_attribute(:comments_count, self.user.comments_count += 1)
+ self.user.inc(:comments_count, 1)
end
def decrement_count
- self.user.comments_count -=1
+ # self.user.update_attribute(:comments_count, self.user.comments_count -= 1)
+ self.user.inc(:comments_count, -1)
end
end
View
2  app/views/users/show.html.erb
@@ -11,6 +11,8 @@
</li>
</ul>
+<h3>Your Comments: <%= @user.comments_count %></h3>
+
<h3>Recent Activities</h3>
<ul class="activities">
Please sign in to comment.
Something went wrong with that request. Please try again.