]> git.openstreetmap.org Git - rails.git/blob - app/controllers/reports_controller.rb
Remove unused update method from issues_controller.
[rails.git] / app / controllers / reports_controller.rb
1 class ReportsController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :require_user
6
7   def new
8     if create_new_report_params.present?
9       @report = Report.new
10       @report.issue = Issue.find_or_initialize_by(create_new_report_params)
11     end
12   end
13
14   def create
15     @report = current_user.reports.new(report_params)
16     @report.issue = Issue.find_or_initialize_by(:reportable_id => params[:report][:issue][:reportable_id], :reportable_type => params[:report][:issue][:reportable_type])
17
18     if @report.save
19       @report.issue.save
20       # FIXME: reopen issue if necessary
21       redirect_to root_path, :notice => t("issues.create.successful_report")
22     else
23       redirect_to new_report_path(:reportable_type => @report.issue.reportable_type, :reportable_id => @report.issue.reportable_id), :notice => t("issues.create.provide_details")
24     end
25   end
26
27   private
28
29   def create_new_report_params
30     params.permit(:reportable_id, :reportable_type)
31   end
32
33   def report_params
34     params[:report].permit(:details, :category)
35   end
36 end