app/controllers/avo/relations_controller.rb in avo-1.24.2 vs app/controllers/avo/relations_controller.rb in avo-1.25.0
- old
+ new
@@ -32,15 +32,25 @@
super
end
def new
- query = @authorization.apply_policy @attachment_class
+ @resource.hydrate(model: @model)
- @options = query.all.map do |model|
- [model.send(@attachment_resource.class.title), model.id]
+ begin
+ @field = @resource.get_field_definitions.find { |f| f.id == @related_resource_name.to_sym }
+ @field.hydrate(resource: @resource, model: @model, view: :new)
+ rescue
end
+
+ if @field.present? && !@field.searchable
+ query = @authorization.apply_policy @attachment_class
+
+ @options = query.all.map do |model|
+ [model.send(@attachment_resource.class.title), model.id]
+ end
+ end
end
def create
if reflection_class == "HasManyReflection"
@model.send(params[:related_name].to_s) << @attachment_model
@@ -48,10 +58,10 @@
@model.send("#{params[:related_name]}=", @attachment_model)
end
respond_to do |format|
if @model.save
- format.html { redirect_to resource_path(model: @model, resource: @resource), notice: t("avo.attachment_class_attached", attachment_class: @attachment_class) }
+ format.html { redirect_to resource_path(model: @model, resource: @resource), notice: t("avo.attachment_class_attached", attachment_class: @related_resource.name) }
format.json { render :show, status: :created, location: resource_path(model: @model, resource: @resource) }
else
format.html { render :new }
format.json { render json: @model.errors, status: :unprocessable_entity }
end