Class: AdminAssistant::Request::AbstractSaving
- Inherits:
-
Object
- Object
- AdminAssistant::Request::AbstractSaving
show all
- Defined in:
- lib/admin_assistant/request/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(record, controller) ⇒ AbstractSaving
Returns a new instance of AbstractSaving.
259
260
261
|
# File 'lib/admin_assistant/request/base.rb', line 259
def initialize(record, controller)
@record, @controller = record, controller
end
|
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
257
258
259
|
# File 'lib/admin_assistant/request/base.rb', line 257
def record
@record
end
|
Instance Method Details
#params_for_save ⇒ Object
263
264
265
|
# File 'lib/admin_assistant/request/base.rb', line 263
def params_for_save
ParamsForSave.new(@controller, @record)
end
|
#record_and_associations_valid? ⇒ Boolean
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/admin_assistant/request/base.rb', line 267
def record_and_associations_valid?
if @controller.respond_to?(:before_validation)
@controller.send(:before_validation, record)
end
params = params_for_save
prepare_record_to_receive_invalid_association_assignments
record.attributes = params
record.valid?
params.errors.each do |attr, msg| record.errors.add(attr, msg); end
if @controller.respond_to?(:validate)
@controller.send(:validate, record)
end
record.errors.empty?
end
|
#redirect_after_save ⇒ Object
282
283
284
285
286
287
288
289
290
291
|
# File 'lib/admin_assistant/request/base.rb', line 282
def redirect_after_save
url_params = if @controller.respond_to?(:destination_after_save)
@controller.send(
:destination_after_save, @record, @controller.params
)
end
url_params ||= @controller.params[:origin]
url_params ||= {:action => 'index'}
@controller.send :redirect_to, url_params
end
|
#save ⇒ Object
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/admin_assistant/request/base.rb', line 293
def save
if @controller.respond_to?(:before_save)
@controller.send(:before_save, record)
end
result = record.save
if result && @controller.respond_to?(:after_save)
@controller.send(:after_save, record)
end
result
end
|