Class: Api::V3::LikesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/v3/likes_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin?, #can?, #current_ability, #current_user, #error!, #error_404!, #optional!, #requires!

Instance Method Details

#createObject

赞一个信息

POST /api/v3/likes

params:

obj_type - [topic, reply]
obj_id - 用于 Push 的设备信息

20
21
22
23
24
# File 'app/controllers/api/v3/likes_controller.rb', line 20

def create
  current_user.like(likeable)
  data = { obj_type: params[:obj_type], obj_id: likeable.id, count: likeable.likes_count }
  render json: data
end

#destroyObject

取消之前的赞

DELETE /api/v3/likes

params:

obj_type - [topic, reply]
obj_id - 用于 Push 的设备信息

35
36
37
38
39
# File 'app/controllers/api/v3/likes_controller.rb', line 35

def destroy
  current_user.unlike(likeable)
  data = { obj_type: params[:obj_type], obj_id: likeable.id, count: likeable.likes_count }
  render json: data
end