Sha256: b44db371c87441e14ef8809ad10dbcfe3ce9af52ae5ae2750cae1f5b746deff3

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module Elabs
  class ReportsController < ElabsApplicationController
    # POST /reports
    # POST /reports.json
    # rubocop:disable Metrics/AbcSize
    def create
      report = complete_report_with_user

      respond_to do |format|
        if report.save
          format.html { redirect_to request.referer, notice: _('Report was successfully created.') }
          format.json { render json: { message: 'ok' }, status: :created, location: report }
        else
          format.html { redirect_to request.referer, notice: { error: report.errors } }
          format.json { render json: report.errors, status: :unprocessable_entity }
        end
      end
    end
    # rubocop:enable Metrics/AbcSize

    private

    # Never trust parameters from the scary internet, only allow the white list through.
    def report_params
      params.require(:report).permit(:name, :email, :reason, :allow_contact)
    end

    def complete_report_with_user
      report = Report.new(report_params)
      report.url = request.referer
      report.user = current_user if user_signed_in?

      report
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elabs-2.0.0 app/controllers/elabs/reports_controller.rb
elabs-2.0.0.pre app/controllers/elabs/reports_controller.rb