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