Class: Api::V3::RepliesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

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

Instance Method Details

#destroyObject

删除回帖

DELETE /api/v3/replies/:id

Raises:


39
40
41
42
43
44
# File 'app/controllers/api/v3/replies_controller.rb', line 39

def destroy
  raise AccessDenied unless can?(:destroy, @reply)

  @reply.destroy
  render json: { ok: 1 }
end

#showObject

获取回帖的详细内容(一般用于编辑回帖的时候)

GET /api/v3/replies/:id


12
13
14
# File 'app/controllers/api/v3/replies_controller.rb', line 12

def show
  render json: @reply, serializer: ReplyDetailSerializer
end

#updateObject

更新回帖

POST /api/v3/replies/:id

params:

body - 回帖内容, [required]

Raises:


24
25
26
27
28
29
30
31
32
# File 'app/controllers/api/v3/replies_controller.rb', line 24

def update
  raise AccessDenied unless can?(:update, @reply)

  requires! :body

  @reply.body = params[:body]
  @reply.save!
  render json: @reply, serializer: ReplyDetailSerializer
end