Class: SkinnyControllers::Operation::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/skinny_controllers/operation/default.rb

Instance Attribute Summary

Attributes inherited from Base

#action, #authorized_via_parent, #current_user, #model_key, #params, #params_for_action

Instance Method Summary collapse

Methods inherited from Base

#allowed?, #allowed_for?, #association_name_from_object, #id_from_params, #initialize, #model_class, #model_name, #policy_class, #policy_for, #policy_method_name, run

Methods included from ModelHelpers

#find_model, #model, #model_from_id, #model_from_named_id, #model_from_params, #model_from_parent, #model_from_scope, #model_param_name, #model_params, #sanitized_params, #scoped_model

Constructor Details

This class inherits a constructor from SkinnyControllers::Operation::Base

Instance Method Details

#runObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/skinny_controllers/operation/default.rb', line 4

def run
  return unless allowed?

  # Note that for explicitly defined operations,
  # There should be a different operation for each
  # action.
  #
  # e.g.:
  #  - EventOperations::Create
  #  - EventOperations::Update
  #  - EventOperations::Destroy
  if creating?
    @model = model_class.new(model_params)
    @model.save
  elsif updating?
    model.update(model_params)
  elsif destroying?
    model.destroy
  end

  model
end