/
factors_controller.rb
78 lines (67 loc) · 2.02 KB
/
factors_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class FactorsController < ApplicationController
before_filter :get_factor, except: [ :new, :create ]
# GET /factors/new
# GET /factors/new.json
def new
@factor = Factor.new
@factor.decision_id = params[:decision_id]
return if ! can_access Decision.find @factor.decision_id
respond_to do |format|
format.html # new.html.erb
format.json { render json: @factor }
end
end
# GET /factors/1/edit
def edit
@factor = Factor.find(params[:id])
end
# POST /factors
# POST /factors.json
def create
@factor = Factor.new(params[:factor])
respond_to do |format|
if @factor && can_access(@factor) && @factor.save
format.html { redirect_to @factor.decision,
notice: 'Factor was successfully created.' }
format.json { render json: @factor, status: :created, location: @factor }
else
format.html { render action: "new" }
format.json { render json: @factor.errors, status: :unprocessable_entity }
end
end
end
# PUT /factors/1
# PUT /factors/1.json
def update
respond_to do |format|
if @factor.update_attributes(params[:factor])
format.html { redirect_to @factor.decision,
notice: 'Factor was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @factor.errors, status: :unprocessable_entity }
end
end
end
# DELETE /factors/1
# DELETE /factors/1.json
def destroy
@factor.destroy
respond_to do |format|
format.html { redirect_to @factor.decision,
notice: 'Factor was successfully removed.' }
format.json { head :ok }
end
end
##############################
## ##
## PRIVATE METHODS BELOW! ##
## ##
##############################
private
def get_factor
@factor = Factor.find params[:id]
@factor = nil if ! can_access @factor
end
end