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



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

def create
  @record = build_record
  set_record_attributes

  if save_record
    redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
  else
    @current_action = ActionInquirer.new!
    @form = form_schema
    @view = new_view
    render :new, status: :bad_request
  end
end

#destroyObject

Deletes a record, or shows validation errors



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/super/application_controller.rb', line 83

def destroy
  @record = load_record

  if destroy_record
    redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
  else
    flash.alert = "Couldn't delete record"
    redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
  end
rescue ActiveRecord::InvalidForeignKey => e
  flash.alert = "Couldn't delete record: #{e.class}"
  redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
end

#editObject

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



61
62
63
64
65
# File 'app/controllers/super/application_controller.rb', line 61

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
29
# 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
  @query_form = initialize_query_form
  initialize_filter_form
  initialize_sort_form
  @records = apply_queries
end

#newObject

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



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

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

#showObject

Displays a specific record to the user



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

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



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/super/application_controller.rb', line 68

def update
  @record = load_record
  set_record_attributes

  if save_record
    redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
  else
    @current_action = ActionInquirer.edit!
    @form = form_schema
    @view = edit_view
    render :edit, status: :bad_request
  end
end