Class: Frigate::Operation::Action::Update

Inherits:
Base
  • Object
show all
Defined in:
lib/frigate/operation/action/update.rb

Overview

Is here to perform update action of operation

Instance Attribute Summary

Attributes inherited from Base

#action_result, #model, #model_form, #operation, #opts, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize, run, #run

Constructor Details

This class inherits a constructor from Frigate::Operation::Action::Base

Instance Method Details

#actionObject

An update action is defined in here



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/frigate/operation/action/update.rb', line 7

def action
  @model = model_klass.find_by_id(params[:id]) # TODO: add id verification
  @model_form = create_form(model)
  if model_form.validate(params)
    if operation_block
      operation_block(model, params)
    else
      model_form.sync_with_model(save: true)
    end
  else
    exception = InvalidParamsError.new('invalid params in %s' % operation.class.name)
    raise (exception.tap { |e| e.errors = model_form.errors })
  end
end