Class: Ems::ReportsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ems/reports_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#createObject

POST /reports POST /reports.json



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/ems/reports_controller.rb', line 47

def create
  @report = Report.new(params[:report])
  
  respond_to do |format|
    if @report.save
      format.html { redirect_to edit_category_report_path(@report.category, @report), notice: 'Report was successfully created.' }
      format.json { render json: @report, status: :created, location: @report }
    else
      format.html { render action: "new", :category_id => @report.category, :id => @report }
      format.json { render json: @report.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /reports/1 DELETE /reports/1.json



79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/ems/reports_controller.rb', line 79

def destroy
  @report = Report.find(params[:id])
  category = @report.category
  @report.destroy
  
  respond_to do |format|
    format.html { redirect_to category_reports_path(category), notice: 'Report was successfully deleted.' }
    format.json { head :no_content }
  end
end

#editObject

GET /reports/1/edit



40
41
42
43
# File 'app/controllers/ems/reports_controller.rb', line 40

def edit
  @report = Report.find(params[:id])
  @report.assets.build
end

#indexObject

GET /reports GET /reports.json



6
7
8
9
10
11
12
13
# File 'app/controllers/ems/reports_controller.rb', line 6

def index
  @reports = Report.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @reports }
  end
end

#newObject

GET /reports/new GET /reports/new.json



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/ems/reports_controller.rb', line 28

def new
  @report = Report.new
  @report.assets.build
  @report.category = Category.find params[:category_id]
  
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @report }
  end
end

#showObject

GET /reports/1 GET /reports/1.json



17
18
19
20
21
22
23
24
# File 'app/controllers/ems/reports_controller.rb', line 17

def show
  @report = Report.find(params[:id])
  
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @report }
  end
end

#updateObject

PUT /reports/1 PUT /reports/1.json



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/ems/reports_controller.rb', line 63

def update
  @report = Report.find(params[:id])
  
  respond_to do |format|
    if @report.update_attributes(params[:report])
      format.html { redirect_to edit_category_report_path(@report.category, @report), notice: 'Report was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit", :category_id => @report.category, :id => @report }
      format.json { render json: @report.errors, status: :unprocessable_entity }
    end
  end
end