Class: Ideasbugs::FeedbacksController

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

Constant Summary collapse

PER_PAGE =
50

Instance Method Summary collapse

Instance Method Details

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 47

def create
  feedback = Feedback.new(feedback_params)
  feedback.user_agent = request.user_agent
  attribute_author(feedback)

  error = attach_screenshots(feedback)
  return render json: { errors: [error] }, status: :unprocessable_entity if error

  if feedback.save
    notify_host(feedback)
    head :created
  else
    render json: { errors: feedback.errors.full_messages }, status: :unprocessable_entity
  end
end

#destroyObject



68
69
70
71
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 68

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

#indexObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 25

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 = Feedback.group(:status).count

  scope = Feedback.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)

  # 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



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

def show; end

#updateObject



63
64
65
66
# File 'app/controllers/ideasbugs/feedbacks_controller.rb', line 63

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