增加 liked_count
This commit is contained in:
parent
0e523d6ff4
commit
bbb3f213f9
|
@ -16,12 +16,12 @@
|
|||
$http.post url
|
||||
.success (res)->
|
||||
if res.success
|
||||
$scope.count += 1
|
||||
$scope.like = $cookies.like = res.id
|
||||
$scope.count = res.count
|
||||
|
||||
$scope.cancel = ->
|
||||
$http.delete url + "/" + $scope.like
|
||||
$http.delete url + "/" + $scope.like, (res)->
|
||||
$scope.count = res.count
|
||||
# anyway, clear cookie
|
||||
delete $cookies["like"]
|
||||
$scope.like = null
|
||||
$scope.get_count()
|
||||
|
|
|
@ -51,7 +51,7 @@ class ArchivesController < ApplicationController
|
|||
type: post.type,
|
||||
created_at: format_date(post.created_at),
|
||||
id: post.id.to_s,
|
||||
liked_count: post.likes.size,
|
||||
liked_count: post.liked_count,
|
||||
visited_count: post.visited_count,
|
||||
labels: post.labels_content
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ class LikesController < ApplicationController
|
|||
|
||||
def index
|
||||
post = Post.find( params[:blog_id] )
|
||||
render :json=> { success: true, count: post.likes.size }
|
||||
render :json=> { success: true, count: post.liked_count }
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -11,9 +11,9 @@ class LikesController < ApplicationController
|
|||
like = Like.new
|
||||
like.post = post
|
||||
if like.save
|
||||
render :json=> { success: true, id: like.id.to_s }
|
||||
render :json=> { success: true, id: like.id.to_s, count: post.liked_count }
|
||||
else
|
||||
render :json=> { success: false }
|
||||
render :json=> { success: false, count: post.liked_count }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,9 +21,9 @@ class LikesController < ApplicationController
|
|||
post = Post.find( params[:blog_id] )
|
||||
like = post.likes.find(params[:id])
|
||||
if like.destroy
|
||||
render :json=> { success: true }
|
||||
render :json=> { success: true, count: post.liked_count }
|
||||
else
|
||||
render :json=> { success: false }
|
||||
render :json=> { success: false, count: post.liked_count }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,4 +41,8 @@ class Post
|
|||
def labels_content
|
||||
self.labels.collect { |label| label.name }.join(", ")
|
||||
end
|
||||
|
||||
def liked_count
|
||||
self.likes.size
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue