Class: Admin::CommentsController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/generators/open_loam/install/templates/admin/comments_controller.rb

Overview

One controller for every commentable entity, because a comment form is the same form whatever it is attached to.

Create only: comments are a record of what was said, so there is no edit and no delete here.

Constant Summary

Constants included from Pagination

Pagination::PER_PAGE

Instance Method Summary collapse

Methods inherited from BaseController

skip_authorization!

Methods included from Pagination

#paginate

Instance Method Details

#create ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/open_loam/install/templates/admin/comments_controller.rb', line 8

def create
  record = commentable

  # Commenting is open to any member — and membership is already proven:
  # BaseController refuses the request otherwise. The policy check is the
  # record's own, so an entity that hides itself from a role hides its
  # discussion too.
  authorize!(policy_for(record), :read?)

  comment = record.open_loam_comments.new(body: params[:body], author: current_actor)
  flash[:alert] = comment.errors.full_messages.to_sentence unless comment.save

  redirect_back fallback_location: [ :admin, record ]
end