Skip to content

Commit

Permalink
update comments_count
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoonk committed Feb 25, 2012
1 parent d903d7f commit 6d59b57
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/comments_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def create
# raise params[:entry_id].inspect # raise params[:entry_id].inspect
@entry = Entry.find(params[:entry_id]) @entry = Entry.find(params[:entry_id])
@comment = Comment.new(params[:comment]) @comment = Comment.new(params[:comment])
@comment.user = current_user
@entry.comments << @comment @entry.comments << @comment
@entry.save @entry.save
respond_to do |format| respond_to do |format|
Expand Down
6 changes: 4 additions & 2 deletions app/models/comment.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class Comment
protected protected


def increment_count 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 end


def decrement_count 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


end end
2 changes: 2 additions & 0 deletions app/views/users/show.html.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
</li> </li>
</ul> </ul>


<h3>Your Comments: <%= @user.comments_count %></h3>

<h3>Recent Activities</h3> <h3>Recent Activities</h3>


<ul class="activities"> <ul class="activities">
Expand Down

0 comments on commit 6d59b57

Please sign in to comment.