Class: Super::ApplicationController

Inherits:
SubstructureController show all
Includes:
ClientError::Handling
Defined in:
app/controllers/super/application_controller.rb

Overview

Provides a default implementation for each of the resourceful actions

Instance Method Summary collapse

Methods inherited from SubstructureController

batch

Instance Method Details

#createObject

Creates a record, or shows the validation errors



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/super/application_controller.rb', line 45

def create
  @record = build_record
  set_record_attributes

  if save_record
    redirect_to_record
  else
    render_new_as_bad_request
  end
end

#destroyObject

Deletes a record, or shows validation errors



76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/super/application_controller.rb', line 76

def destroy
  @record = load_record

  if destroy_record
    redirect_to_records
  else
    redirect_to_record_with_destroy_failure_message
  end
rescue ActiveRecord::ActiveRecordError => e
  redirect_to_record_with_destroy_failure_message(e)
end

#editObject

Displays a form to allow the user to update an existing record



57
58
59
60
61
# File 'app/controllers/super/application_controller.rb', line 57

def edit
  @record = load_record
  @form = form_schema
  @view = edit_view
end

#indexObject

Displays a list of records to the user



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/super/application_controller.rb', line 15

def index
  if request.format.ref == :csv && !csv_enabled?
    params_for_rebuilding_url = params.to_unsafe_hash
    params_for_rebuilding_url.delete("format")
    return redirect_to params_for_rebuilding_url
  end

  @records = load_records
  @display = display_schema.apply(action: current_action, format: request.format)
  @view = index_view
  initialize_filter_form
  initialize_sort_form
  @records = apply_queries
end

#newObject

Displays a form to allow the user to create a new record



38
39
40
41
42
# File 'app/controllers/super/application_controller.rb', line 38

def new
  @record = build_record
  @form = form_schema
  @view = new_view
end

#showObject

Displays a specific record to the user



31
32
33
34
35
# File 'app/controllers/super/application_controller.rb', line 31

def show
  @record = load_record
  @display = display_schema.apply(action: current_action, format: request.format)
  @view = show_view
end

#updateObject

Updates a record, or shows validation errors



64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/super/application_controller.rb', line 64

def update
  @record = load_record
  set_record_attributes

  if save_record
    redirect_to_record
  else
    render_edit_as_bad_request
  end
end