Class: CreationController

Inherits:
ApplicationController show all
Defined in:
app/controllers/creation_controller.rb

Overview

Base class for labware creation. Inherited by PlateCreationController and TubeCreationController. Controllers find the appropriate LabwareCreator specified by the purpose configuration new => renders the form specified by the labware creator,

This usually indicates that further information needs to be supplied by the user,
or that we need to display an interstitial page

create => Use the specified labware creator to generate the resource. Will usually redirect

to the asset that has just been created, but may redirect to the parent if there are multiple children.

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
# File 'app/controllers/creation_controller.rb', line 21

def create
  creator_params[:parent_uuid] ||= parent_uuid
  @labware_creator = labware_creator(creator_params)
  @labware_creator.save ? create_success : create_failure
end

#creation_failed(exception) ⇒ Object



31
32
33
34
35
36
37
# File 'app/controllers/creation_controller.rb', line 31

def creation_failed(exception)
  Rails.logger.error("Cannot create child of #{@labware_creator.parent.uuid}")
  Rails.logger.error(exception.message)
  exception.backtrace.map(&Rails.logger.method(:error)) # rubocop:todo Performance/MethodObjectAsBlock

  redirect_back_after_error('Cannot create the next piece of labware:', exception.resource.errors.full_messages)
end

#labware_creator(form_attributes) ⇒ Object



27
28
29
# File 'app/controllers/creation_controller.rb', line 27

def labware_creator(form_attributes)
  creator_class.new(api, form_attributes.permit(permitted_attributes).merge(params_for_creator_build))
end

#newObject



15
16
17
18
19
# File 'app/controllers/creation_controller.rb', line 15

def new
  params[:parent_uuid] ||= parent_uuid
  @labware_creator = labware_creator(params.permit(permitted_attributes))
  respond_to { |format| format.html { render(@labware_creator.page) } }
end

#sequencescape_api_server_error(exception) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/creation_controller.rb', line 39

def sequencescape_api_server_error(exception)
  Rails.logger.error("Cannot create child of #{@labware_creator.parent.uuid}, Sequencescape api server error(s)")
  Rails.logger.error(exception.message)
  exception.backtrace.map(&Rails.logger.method(:error)) # rubocop:todo Performance/MethodObjectAsBlock

  api_error_messages = extract_error_messages_from_api_exception(exception.message)

  redirect_back_after_error(
    'Cannot create the next piece of labware, Sequencescape server API error(s):',
    api_error_messages
  )
end