Class: Ideasbugs::FeedbacksController

Inherits:
DashboardController show all
Defined in:
app/controllers/ideasbugs/feedbacks_controller.rb

Constant Summary collapse

PER_PAGE =
50

Instance Method Summary collapse

Instance Method Details

#destroyObject



39
40
41
42
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 39

def destroy
  @feedback.destroy!
  redirect_to root_path, status: :see_other
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 10

def index
  @status = Feedback::STATUSES.include?(params[:status]) ? params[:status] : 'open'
  @kind = Ideasbugs.config.kinds.map(&:to_s).include?(params[:kind]) ? params[:kind] : nil
  @query = params[:q].to_s.strip.presence
  @counts = tenant_scope.group(:status).count

  scope = tenant_scope.where(status: @status)
  scope = scope.where(kind: @kind) if @kind
  scope = search(scope) if @query
  @page = [params[:page].to_i, 1].max
  @feedbacks = scope.newest_first.offset((@page - 1) * PER_PAGE).limit(PER_PAGE + 1).to_a
  @more = @feedbacks.size > PER_PAGE
  @feedbacks = @feedbacks.first(PER_PAGE)

  @selected_feedback = tenant_scope.find_by(id: params[:feedback_id]) if params[:feedback_id].present?

  # Only surface the Section column when it can carry information: the host
  # configured sections, or some record already has one (e.g. sections were
  # configured historically). Otherwise it's a permanently blank column.
  @show_section = Ideasbugs.config.sections.any? || @feedbacks.any? { |f| f.section.present? }
end

#showObject



32
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 32

def show; end

#updateObject



34
35
36
37
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 34

def update
  @feedback.update!(params.require(:feedback).permit(:status))
  redirect_back fallback_location: feedback_path(@feedback), status: :see_other
end