Class: AbstractResourcesController
Instance Method Summary
collapse
#find_parent, #parent, #parent?, #parent_class, #parent_class=, #parent_url, #recognise_parent, #recognise_path, #recognise_resource, #set_parents, #update_parenthood
#_filter, #_flip, #_id, #_paginate, #_search, #_sort, #find_all_resources, #find_resources, #find_resources_queried, #new_resource, #resource, #resource?, #resource_class, #resource_class=, #resource_name, #resource_options, #resource_params, #resource_url, #resources, #resources_url, #set_resource, #set_resources, #sorting_direction
#display_print_result, #download_print_result, #email_print_result, #print, #print_print_result, #print_resources
#user_not_authorized
Instance Method Details
#activate ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/controllers/abstract_resources_controller.rb', line 52
def activate
authorize resource
if resource.activate
flash[:info] = t(:resource_activated_correct)
render :activate, layout: false, status: 200 and return
else
flash[:error] = t(:resource_activated_incorrect)
render :activate, layout: false, status: 401 and return
end
rescue Exception => e
scoop_from_error e
end
|
#attach ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/abstract_resources_controller.rb', line 81
def attach
authorize resource
if resource.attach parent
flash[:info] = t(:resource_attached_correct)
render :attach, layout: false, status: 200 and return
else
flash[:error] = t(:resource_attached_incorrect)
render :attach, layout: false, status: 401 and return
end
rescue Exception => e
scoop_from_error e
end
|
#create ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'app/controllers/abstract_resources_controller.rb', line 143
def create
authorize resource
@resource = Photo.create resource_params
Rails.logger.info "--------------------------------------------- Added Photo ##{@resource.id}"
render :create and return
respond_with(resource, location: redirect_after_create ) do |format|
if resource.save && update_parenthood
flash[:notice] = t('.success.created', resource: resource_class.to_s )
else
format.html { render action: :new, status: :unprocessable_entity }
format.js { render action: :new, status: :unprocessable_entity }
end
end
rescue Exception => e
scoop_from_error e
end
|
#deactivate ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/controllers/abstract_resources_controller.rb', line 66
def deactivate
authorize resource
if resource.deactivate
flash[:info] = t(:resource_deactivated_correct)
render :deactivate, layout: false, status: 200 and return
else
flash[:error] = t(:resource_deactivated_incorrect)
render :deactivate, layout: false, status: 401 and return
end
rescue Exception => e
scoop_from_error e
end
|
#defer ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/abstract_resources_controller.rb', line 38
def defer
authorize resource
if resource.defer parent
flash[:info] = t(:resource_deferred_correct)
render :defer, layout: false, status: 200 and return
else
flash[:error] = t(:resource_deferred_incorrect)
render :defer, layout: false, status: 401 and return
end
rescue Exception => e
scoop_from_error e
end
|
#destroy ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'app/controllers/abstract_resources_controller.rb', line 175
def destroy
authorize resource
result = true if delete_resource && update_parenthood
result ? (flash.now[:notice] = t('.success', resource: resource_class.to_s)) : (flash.now[:error] = t('.deleted.error',resource: resource_class.to_s) + " " + resource.errors.messages.values.join( " / "))
if result==true
render layout:false, status: 200, locals: { result: true }
else
render layout:false, status: 301, locals: { result: true, errors: resource.errors.messages.values.join( " / ") }
end
rescue Exception => e
scoop_from_error e
end
|
#detach ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/controllers/abstract_resources_controller.rb', line 95
def detach
authorize resource
if resource.detach parent
flash[:info] = t(:resource_detached_correct)
render :detach, layout: false, status: 200 and return
else
flash[:error] = t(:resource_detached_incorrect)
render :detach, layout: false, status: 401 and return
end
rescue Exception => e
scoop_from_error e
end
|
#edit ⇒ Object
124
125
126
127
128
129
|
# File 'app/controllers/abstract_resources_controller.rb', line 124
def edit
authorize resource
respond_with resource
rescue Exception => e
scoop_from_error e
end
|
#index ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
|
# File 'app/controllers/abstract_resources_controller.rb', line 131
def index
authorize resource_class, :index?
respond_with resources do |format|
end
rescue Exception => e
scoop_from_error e
end
|
#new ⇒ Object
116
117
118
119
120
121
122
|
# File 'app/controllers/abstract_resources_controller.rb', line 116
def new
resource.parent_id = params[:parent_id] if resource.respond_to? :parent_id
authorize resource
respond_with resource
rescue Exception => e
scoop_from_error e
end
|
#prefer ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/abstract_resources_controller.rb', line 24
def prefer
authorize resource
if resource.prefer parent
flash[:info] = t(:resource_preferred_correct)
render :prefer, layout: false, status: 200 and return
else
flash[:error] = t(:resource_preferred_incorrect)
render :prefer, layout: false, status: 401 and return
end
rescue Exception => e
scoop_from_error e
end
|
#show ⇒ Object
109
110
111
112
113
114
|
# File 'app/controllers/abstract_resources_controller.rb', line 109
def show
authorize resource
respond_with resource
rescue Exception => e
scoop_from_error e
end
|
#update ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'app/controllers/abstract_resources_controller.rb', line 161
def update
authorize resource
respond_with(resource, location: redirect_after_update) do |format|
if resource.update_attributes(resource_params) && update_parenthood
flash[:notice] = t('.success.updated', resource: resource_class.to_s )
else
format.html { render action: :edit, status: :unprocessable_entity }
format.js { render action: :edit, status: :unprocessable_entity }
end
end
rescue Exception => e
scoop_from_error e
end
|