Class: AdminAssistant::Request::CreateSaving

Inherits:
AbstractSaving show all
Defined in:
lib/admin_assistant/request/create.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractSaving

#record

Instance Method Summary collapse

Methods inherited from AbstractSaving

#record_and_associations_valid?, #redirect_after_save

Constructor Details

#initialize(record, controller, params_prefix = nil) ⇒ CreateSaving

Returns a new instance of CreateSaving.



41
42
43
44
# File 'lib/admin_assistant/request/create.rb', line 41

def initialize(record, controller, params_prefix = nil)
  super record, controller
  @params_prefix = params_prefix
end

Instance Attribute Details

#params_prefixObject (readonly)

Returns the value of attribute params_prefix.



39
40
41
# File 'lib/admin_assistant/request/create.rb', line 39

def params_prefix
  @params_prefix
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/admin_assistant/request/create.rb', line 46

def blank?
  raw_params.values.all? &:blank?
end

#params_for_saveObject



50
51
52
# File 'lib/admin_assistant/request/create.rb', line 50

def params_for_save
  ParamsForSave.new @controller, @record, raw_params
end

#prepare_record_to_receive_invalid_association_assignmentsObject



54
55
56
# File 'lib/admin_assistant/request/create.rb', line 54

def prepare_record_to_receive_invalid_association_assignments
  # no preparations necessary for creation
end

#raw_paramsObject



58
59
60
61
# File 'lib/admin_assistant/request/create.rb', line 58

def raw_params
  model_class_symbol = @record.class.name.underscore.to_sym
  @controller.params[model_class_symbol][@params_prefix]
end

#saveObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/admin_assistant/request/create.rb', line 63

def save
  if @controller.respond_to?(:before_create)
    @controller.send(:before_create, @record)
  end
  result = super
  if @controller.respond_to?(:after_create)
    @controller.send(:after_create, @record)
  end
  result
end