Class: Super::ApplicationController
- Inherits:
-
SubstructureController
- Object
- ActionController::Base
- SubstructureController
- 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.
Methods inherited from SubstructureController
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
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 |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#show ⇒ Object
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 |
#update ⇒ Object
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 |