Skip to content

Commit

Permalink
extract url from associations view to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Sep 28, 2024
1 parent 79bb17f commit b85d951
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 10 additions & 0 deletions app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def new
[@attachment_resource.new(record: record).record_title, record.to_param]
end
end

@url = Avo::Services::URIService.parse(avo.root_url.to_s)
.append_paths('resources', params[:resource_name], params[:id], params[:related_name])
.append_query(
{
view: @resource&.view&.to_s,
for_attribute: @field&.try(:for_attribute)
}.compact
)
.to_s
end

def create
Expand Down
13 changes: 1 addition & 12 deletions app/views/avo/associations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
<%= turbo_frame_tag Avo::MODAL_FRAME_ID do %>
<%
url = Avo::Services::URIService.parse(avo.root_url.to_s)
.append_paths('resources', params[:resource_name], params[:id], params[:related_name])
.append_query(
{
view: @resource&.view&.to_s,
for_attribute: @field&.try(:for_attribute)
}.compact
)
.to_s
%>
<%= form_with scope: 'fields',
url: url,
url: @url,
local: true,
data: {
turbo_frame: :_top
Expand Down

0 comments on commit b85d951

Please sign in to comment.