Module: Raport::Reportify

Extended by:
ActiveSupport::Concern
Defined in:
lib/raport/concerns/controllers/reportify.rb

Instance Method Summary collapse

Instance Method Details

#create_reportObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/raport/concerns/controllers/reportify.rb', line 15

def create_report
  if Raport.config.formats.include?(request.format.to_sym)
    @report = current_report_owner.reports.create(report_attributes)

    respond_to do |format|
      format.any do 
        if request.xhr?
          json = @report.errors.empty? ? @report.as_json(methods: :permalink) : { errors: @report.errors }.to_json
          render json: json
        else
          redirect_to polymorphic_path([current_namespace, @report])
        end
      end
    end
  end
end

#current_report_ownerObject



11
12
13
# File 'lib/raport/concerns/controllers/reportify.rb', line 11

def current_report_owner
  current_user
end