Class: Avo::AssociationsController
Instance Method Summary
collapse
#edit, #update
#_current_user, #check_avo_license, #context, #exception_logger, #init_app, #render, #turbo_frame_request?
Methods included from UrlHelpers
#edit_resource_path, #new_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resources_path
#a_button, #a_link, #button_classes, #empty_state, #get_model_class, #input_classes, #render_license_warning, #render_license_warnings, #root_path_without_url, #svg
Instance Method Details
#create ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/avo/associations_controller.rb', line 59
def create
if reflection_class == "HasManyReflection"
@model.send(params[:related_name].to_s) << @attachment_model
else
@model.send("#{params[:related_name]}=", @attachment_model)
end
respond_to do |format|
if @model.save
format.html { redirect_back fallback_location: resource_path(model: @model, resource: @resource), notice: t("avo.attachment_class_attached", attachment_class: @related_resource.name) }
else
format.html { render :new }
end
end
end
|
#destroy ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/avo/associations_controller.rb', line 75
def destroy
if reflection_class == "HasManyReflection"
@model.send(params[:related_name].to_s).delete @attachment_model
else
@model.send("#{params[:related_name]}=", nil)
end
respond_to do |format|
format.html { redirect_to params[:referrer] || resource_path(model: @model, resource: @resource), notice: t("avo.attachment_class_detached", attachment_class: @attachment_class) }
end
end
|
#index ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/avo/associations_controller.rb', line 19
def index
@parent_resource = @resource.dup
@resource = @related_resource
@parent_model = @parent_resource.class.find_scope.find(params[:id])
@parent_resource.hydrate(model: @parent_model)
@query = @authorization.apply_policy @parent_model.public_send(params[:related_name])
@association_field = @parent_resource.get_field params[:related_name]
if @association_field.present? && @association_field.scope.present?
@query = Avo::Hosts::AssociationScopeHost.new(block: @association_field.scope, query: @query, parent: @parent_model).handle
end
super
end
|
#new ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/controllers/avo/associations_controller.rb', line 42
def new
@resource.hydrate(model: @model)
if @field.present? && !@field.searchable
query = @authorization.apply_policy @attachment_class
if @field.attach_scope.present?
query = Avo::Hosts::AssociationScopeHost.new(block: @field.attach_scope, query: query, parent: @model).handle
end
@options = query.all.map do |model|
[model.send(@attachment_resource.class.title), model.id]
end
end
end
|
#order ⇒ Object
87
88
89
90
91
92
|
# File 'app/controllers/avo/associations_controller.rb', line 87
def order
@parent_resource = @resource.dup
@resource, @model = @related_resource, @related_model
super
end
|
#show ⇒ Object
34
35
36
37
38
39
40
|
# File 'app/controllers/avo/associations_controller.rb', line 34
def show
@parent_resource, @parent_model = @resource, @model
@resource, @model = @related_resource, @related_model
super
end
|