From 9c380ac61ba11f4d772f60a1c9009ff0ed74b818 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Thu, 4 Apr 2024 19:59:46 +0300 Subject: [PATCH] fix: hydrate resource with record when detect_fields on new (#2659) * fix: hydrate resource with record when detect_fields on new * refactor * wip * fix --- app/controllers/avo/base_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index d921b94a9e..b467441893 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -8,8 +8,8 @@ class BaseController < ApplicationController before_action :set_resource before_action :set_applied_filters, only: :index before_action :set_record, only: [:show, :edit, :destroy, :update, :preview] + before_action :set_record_to_fill, only: [:new, :edit, :create, :update] before_action :detect_fields - before_action :set_record_to_fill before_action :set_edit_title_and_breadcrumbs, only: [:edit, :update] before_action :fill_record, only: [:create, :update] # Don't run base authorizations for associations @@ -102,8 +102,9 @@ def show end def new - @record = @resource.model_class.new - @resource = @resource.hydrate(record: @record, view: :new, user: _current_user) + # Record is already hydrated on set_record_to_fill method + @record = @resource.record + @resource.hydrate(view: :new, user: _current_user) # Handle special cases when creating a new record via a belongs_to relationship if params[:via_belongs_to_resource_class].present?