Module: JunglePath::Controller::Helpers::Key

Defined in:
lib/jungle_path/controller/helpers.rb

Instance Method Summary collapse

Instance Method Details

#initialize(current_identity, params, db, model_class) ⇒ Object



28
29
30
# File 'lib/jungle_path/controller/helpers.rb', line 28

def initialize(current_identity, params, db, model_class)
  super(current_identity, params, db, model_class)
end

#insert(include_secure_columns: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jungle_path/controller/helpers.rb', line 32

def insert(include_secure_columns: false)
  id = @params[:id]
  key = @db.select._model(@table_class.new({id: id})) if id
  if key #exists already, do update.
    key._consume_hash(@params) # overwrite current values with new values
    @params = key.to_hash # put all in @params for update
    update
    key = @db.select._model(key) # return updated object from database.
  else
    super
  end
end