Class: Avo::AssociationsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Avo::AssociationsController
- Defined in:
- app/controllers/avo/associations_controller.rb
Instance Method Summary collapse
Methods inherited from BaseController
Methods included from Concerns::FiltersSessionHandler
#cache_resource_filters?, #fetch_filters, #filters_from_params, #filters_from_session, #filters_session_key, #reset_filters, #save_filters_to_session
Methods inherited from ApplicationController
#exception_logger, #turbo_frame_request?
Methods included from Concerns::Breadcrumbs
#add_breadcrumb, #avo_breadcrumbs
Methods included from UrlHelpers
#edit_resource_path, #new_resource_path, #preview_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resource_view_path, #resources_path
Methods included from ApplicationHelper
#a_button, #a_link, #button_classes, #chart_color, #decode_filter_params, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #render_license_warning, #root_path_without_url, #svg, #white_panel_classes
Methods included from ResourcesHelper
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table
Methods included from InitializesAvo
#_current_user, #context, #init_app
Instance Method Details
#create ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/avo/associations_controller.rb', line 60 def create association_name = BaseResource.valid_association_name(@record, params[:related_name]) if reflection_class == "HasManyReflection" @record.send(association_name) << else @record.send("#{association_name}=", ) end respond_to do |format| if @record.save format.html { redirect_back fallback_location: resource_view_response_path, notice: t("avo.attachment_class_attached", attachment_class: .name) } else format.html { render :new } end end end |
#destroy ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/avo/associations_controller.rb', line 78 def destroy association_name = BaseResource.valid_association_name(@record, params[:related_name]) if reflection_class == "HasManyReflection" @record.send(association_name).delete else @record.send(:"#{association_name}=", nil) end respond_to do |format| format.html { redirect_to params[:referrer] || resource_view_response_path, notice: t("avo.attachment_class_detached", attachment_class: ) } end end |
#index ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/avo/associations_controller.rb', line 19 def index @parent_resource = @resource.dup @resource = @parent_record = @parent_resource.find_record(params[:id], params: params) @parent_resource.hydrate(record: @parent_record) association_name = BaseResource.valid_association_name(@parent_record, params[:related_name]) @query = .apply_policy @parent_record.send(association_name) @association_field = @parent_resource.get_field params[:related_name] if @association_field.present? && @association_field.scope.present? @query = Avo::ExecutionContext.new(target: @association_field.scope, query: @query, parent: @parent_record).handle end super end |
#new ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/avo/associations_controller.rb', line 43 def new @resource.hydrate(record: @record) if @field.present? && !@field.is_searchable? query = .apply_policy # Add the association scope to the query scope if @field.attach_scope.present? query = Avo::ExecutionContext.new(target: @field.attach_scope, query: query, parent: @record).handle end = query.all.map do |record| [.new(record: record).record_title, record.id] end end end |
#show ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/controllers/avo/associations_controller.rb', line 35 def show @parent_resource, @parent_record = @resource, @record @resource, @record = , super end |