<commit_before>module ActiveScaffold::Actions
  module Core
    def self.included(base)
      base.class_eval do
        before_action :set_vary_accept_header
        before_action :check_input_device
        before_action :register_constraints_with_action_columns, :unless => :nested?
        after_action :clear_flashes
        around_action :clear_storage
        rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access
      end
      base.helper_method :active_scaffold_config
      base.helper_method :successful?
      base.helper_method :nested?
      base.helper_method :grouped_search?
      base.helper_method :embedded?
      base.helper_method :loading_embedded?
      base.helper_method :calculate_query
      base.helper_method :new_model
      base.helper_method :touch_device?
      base.helper_method :hover_via_click?
    end

    def render_field
      if request.get?
        render_field_for_inplace_editing
        respond_to do |format|
          format.js { render :action => 'render_field_inplace', :layout => false }
        end
      else
        render_field_for_update_columns
        respond_to { |format| format.js }
      end
    end

    protected

    def loading_embedded?
      @loading_embedded ||= active_scaffold_embedded_params.delete(:loading)
    end

    def embedded?
      params[:eid]
    end

    def nested?
      false
    end

    def grouped_search?
      false
    end

    def render_field_for_inplace_editing
      @column = active_scaffold_config.columns[params[:update_column]]
      @record = find_if_allowed(params[:id], :crud_type => :update, :column => params[:update_column])
    end

    def render_field_for_update_columns
      return if (@column = active_scaffold_config.columns[params.delete(:column)]).nil?
      @source_id = params.delete(:source_id)
      @columns = @column.update_columns || []
      @scope = params.delete(:scope)
      action = :subform if @scope
      action ||= params[:id] ? :update : :create
      @main_columns = active_scaffold_config.send(action).columns
      @columns << @column.name if @column.options[:refresh_link] && @columns.exclude?(@column.name)

      @record =
        if @column.send_form_on_update_column
          updated_record_with_form(@main_columns, params[:record], @scope)
        else
          updated_record_with_column(@column, params.delete(:value), @scope)
        end
      setup_parent(@record) if main_form_controller && @scope
      after_render_field(@record, @column)
    end

    def updated_record_with_form(columns, attributes, scope)
      if attributes && scope
        attributes = scope.delete('[').split(']').inject(attributes) { |h, idx| h[idx] }
        id = attributes[:id]
      else
        id = params[:id]
      end
<commit_msg>fix render field for subforms inside subform, setup_parent is never possible, so prevent failing when association is found because there is a through association<commit_after>module ActiveScaffold::Actions
  module Core
    def self.included(base)
      base.class_eval do
        before_action :set_vary_accept_header
        before_action :check_input_device
        before_action :register_constraints_with_action_columns, :unless => :nested?
        after_action :clear_flashes
        around_action :clear_storage
        rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access
      end
      base.helper_method :active_scaffold_config
      base.helper_method :successful?
      base.helper_method :nested?
      base.helper_method :grouped_search?
      base.helper_method :embedded?
      base.helper_method :loading_embedded?
      base.helper_method :calculate_query
      base.helper_method :new_model
      base.helper_method :touch_device?
      base.helper_method :hover_via_click?
    end

    def render_field
      if request.get?
        render_field_for_inplace_editing
        respond_to do |format|
          format.js { render :action => 'render_field_inplace', :layout => false }
        end
      else
        render_field_for_update_columns
        respond_to { |format| format.js }
      end
    end

    protected

    def loading_embedded?
      @loading_embedded ||= active_scaffold_embedded_params.delete(:loading)
    end

    def embedded?
      params[:eid]
    end

    def nested?
      false
    end

    def grouped_search?
      false
    end

    def render_field_for_inplace_editing
      @column = active_scaffold_config.columns[params[:update_column]]
      @record = find_if_allowed(params[:id], :crud_type => :update, :column => params[:update_column])
    end

    def render_field_for_update_columns
      return if (@column = active_scaffold_config.columns[params.delete(:column)]).nil?
      @source_id = params.delete(:source_id)
      @columns = @column.update_columns || []
      @scope = params.delete(:scope)
      action = :subform if @scope
      action ||= params[:id] ? :update : :create
      @main_columns = active_scaffold_config.send(action).columns
      @columns << @column.name if @column.options[:refresh_link] && @columns.exclude?(@column.name)

      @record =
        if @column.send_form_on_update_column
          updated_record_with_form(@main_columns, params[:record], @scope)
        else
          updated_record_with_column(@column, params.delete(:value), @scope)
        end
      # if @scope has more than 2 ] then it's subform inside subform, and assign parent would fail (found associotion may be through association)
      setup_parent(@record) if main_form_controller && @scope && @scope.scan(']').size == 2
      after_render_field(@record, @column)
    end

    def updated_record_with_form(columns, attributes, scope)
      if attributes && scope
        attributes = scope.delete('[').split(']').inject(attributes) { |h, idx| h[idx] }
        id = attributes[:id]
      else
        id = params[:id]
      end

{'fraction_non_alphanumeric': 0.09144295302013423, 'fraction_numerical': 0.0003355704697986577, 'mean_word_length': 3.1453407510431153, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1866104', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1732, 'n_words': 369}