Class: Pbw::BaseModelsController
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#model_class ⇒ Object
Returns the value of attribute model_class.
5
6
7
|
# File 'app/controllers/pbw/base_models_controller.rb', line 5
def model_class
@model_class
end
|
Instance Method Details
#create ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/controllers/pbw/base_models_controller.rb', line 51
def create
if @model.save
respond_with(@model) do |format|
format.json { render json: @model }
end
else
respond_with(@model) do |format|
format.json { render json: @model.errors.full_messages, status: :unprocessable_entity}
end
end
end
|
#destroy ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/pbw/base_models_controller.rb', line 75
def destroy
if @model.destroy
respond_with(@model) do |format|
format.json { head :no_content }
end
else
respond_with(@model) do |format|
format.json { render json: @model.errors.full_messages, status: :unprocessable_entity}
end
end
end
|
#edit ⇒ Object
39
40
41
42
43
|
# File 'app/controllers/pbw/base_models_controller.rb', line 39
def edit
respond_with(@model) do |format|
format.json { render json: @model }
end
end
|
#index ⇒ Object
26
27
28
29
30
31
|
# File 'app/controllers/pbw/base_models_controller.rb', line 26
def index
session[:referrer] = request.url
respond_with(@models) do |format|
format.json { render json: @models }
end
end
|
#index_models ⇒ Object
106
107
108
109
|
# File 'app/controllers/pbw/base_models_controller.rb', line 106
def index_models
authorize! :manage, model_class
@models = model_class.desc(:created_at)
end
|
#model_for_create ⇒ Object
111
112
113
114
115
|
# File 'app/controllers/pbw/base_models_controller.rb', line 111
def model_for_create
authorize! :create, real_model_class
@model = real_model_class.new(params[model_param])
update_model_before_create(@model)
end
|
#model_for_read ⇒ Object
117
118
119
120
|
# File 'app/controllers/pbw/base_models_controller.rb', line 117
def model_for_read
@model = model_class.find(model_id)
authorize! :read, @model
end
|
#model_for_update ⇒ Object
122
123
124
125
126
|
# File 'app/controllers/pbw/base_models_controller.rb', line 122
def model_for_update
@model = model_class.find(model_id)
authorize! :update, @model
update_model_before_update(@model)
end
|
#model_id ⇒ Object
102
103
104
|
# File 'app/controllers/pbw/base_models_controller.rb', line 102
def model_id
params[:id]
end
|
#model_param ⇒ Object
98
99
100
|
# File 'app/controllers/pbw/base_models_controller.rb', line 98
def model_param
model_class.name.underscore.downcase.to_sym
end
|
#new ⇒ Object
45
46
47
48
49
|
# File 'app/controllers/pbw/base_models_controller.rb', line 45
def new
respond_with(@model) do |format|
format.json { render json: @model }
end
end
|
#real_model_class ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'app/controllers/pbw/base_models_controller.rb', line 87
def real_model_class
begin
unless params[:_type].blank?
klass = Kernel.get_const(params[:_type])
return klass if klass.ancestors.include?(self.model_class)
end
rescue
end
self.model_class
end
|
#set_model_class ⇒ Object
14
15
16
|
# File 'app/controllers/pbw/base_models_controller.rb', line 14
def set_model_class
end
|
#show ⇒ Object
33
34
35
36
37
|
# File 'app/controllers/pbw/base_models_controller.rb', line 33
def show
respond_with(@model) do |format|
format.json { render json: @model }
end
end
|
#update ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/pbw/base_models_controller.rb', line 63
def update
if @model.update_attributes(params[model_param])
respond_with(@model) do |format|
format.json { render json: @model }
end
else
respond_with(@model) do |format|
format.json { render json: @model.errors.full_messages, status: :unprocessable_entity}
end
end
end
|
#update_model_before_create(model) ⇒ Object
18
19
20
|
# File 'app/controllers/pbw/base_models_controller.rb', line 18
def update_model_before_create(model)
end
|
#update_model_before_update(model) ⇒ Object
22
23
24
|
# File 'app/controllers/pbw/base_models_controller.rb', line 22
def update_model_before_update(model)
end
|