Class: Super::ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Super::ApplicationController
- 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
-
#create ⇒ Object
Creates a record, or shows the validation errors.
-
#destroy ⇒ Object
Deletes a record, or shows validation errors.
-
#edit ⇒ Object
Displays a form to allow the user to update an existing record.
-
#index ⇒ Object
Displays a list of records to the user.
-
#new ⇒ Object
Displays a form to allow the user to create a new record.
-
#show ⇒ Object
Displays a specific record to the user.
-
#update ⇒ Object
Updates a record, or shows validation errors.
Instance Method Details
#create ⇒ Object
Creates a record, or shows the validation errors
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/super/application_controller.rb', line 37 def create @record = controls.build_record_with_params(action: action_inquirer, params: params) if controls.save_record(action: action_inquirer, record: @record, params: params) redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record)) else @form = controls.form_schema(action: action_inquirer_for("new")) @view = controls.new_view render :new, status: :bad_request end end |
#destroy ⇒ Object
Deletes a record, or shows validation errors
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/super/application_controller.rb', line 70 def destroy @record = controls.load_record(action: action_inquirer, params: params) if controls.destroy_record(action: action_inquirer, record: @record, params: params) 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 |
#edit ⇒ Object
Displays a form to allow the user to update an existing record
50 51 52 53 54 |
# File 'app/controllers/super/application_controller.rb', line 50 def edit @record = controls.load_record(action: action_inquirer, params: params) @form = controls.form_schema(action: action_inquirer) @view = controls.edit_view end |
#index ⇒ Object
Displays a list of records to the user
12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/super/application_controller.rb', line 12 def index @records = controls.load_records(action: action_inquirer, params: params) @display = controls.display_schema(action: action_inquirer).apply(action: action_inquirer) @view = controls.index_view @query_form = controls.initialize_query_form(params: params, current_path: request.path) controls.initialize_filter_form(query_form: @query_form) controls.initialize_sort_form(query_form: @query_form) @records = controls.apply_queries(query_form: @query_form, records: @records) end |
#new ⇒ Object
Displays a form to allow the user to create a new record
30 31 32 33 34 |
# File 'app/controllers/super/application_controller.rb', line 30 def new @record = controls.build_record(action: action_inquirer) @form = controls.form_schema(action: action_inquirer) @view = controls.new_view end |
#show ⇒ Object
Displays a specific record to the user
23 24 25 26 27 |
# File 'app/controllers/super/application_controller.rb', line 23 def show @record = controls.load_record(action: action_inquirer, params: params) @display = controls.display_schema(action: action_inquirer).apply(action: action_inquirer) @view = controls.show_view end |
#update ⇒ Object
Updates a record, or shows validation errors
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/super/application_controller.rb', line 57 def update @record = controls.load_record(action: action_inquirer, params: params) if controls.update_record(action: action_inquirer, record: @record, params: params) redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record)) else @form = controls.form_schema(action: action_inquirer_for("edit")) @view = controls.edit_view render :edit, status: :bad_request end end |