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

Instance Method Details

#createObject

Creates a record, or shows the validation errors



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/super/application_controller.rb', line 36

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



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

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



51
52
53
54
55
# File 'app/controllers/super/application_controller.rb', line 51

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

#indexObject

Displays a list of records to the user



11
12
13
14
15
16
17
18
19
# File 'app/controllers/super/application_controller.rb', line 11

def index
  @records = load_records
  @display = display_schema.apply(action: current_action)
  @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



29
30
31
32
33
# File 'app/controllers/super/application_controller.rb', line 29

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

#showObject

Displays a specific record to the user



22
23
24
25
26
# File 'app/controllers/super/application_controller.rb', line 22

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

#updateObject

Updates a record, or shows validation errors



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/super/application_controller.rb', line 58

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