Module: AutoStrongParameters::AutoFormParams

Extended by:
ActiveSupport::Concern
Defined in:
lib/auto_strong_parameters/auto_form_params.rb

Constant Summary collapse

ASP_NAME_REGEX =
/\bname=\"(.+?)\"/
ASP_DIGIT_REGEX =
/\[\d+\]/
TRACKED_FIELDS =
%w(
  check_box
  collection_check_boxes
  collection_radio_buttons
  collection_select
  color_field
  date_field
  datetime_field
  datetime_local_field
  email_field
  file_field
  grouped_collection_select
  hidden_field
  month_field
  number_field
  password_field
  phone_field
  radio_button
  range_field
  rich_text_area
  rich_textarea
  search_field
  select
  telephone_field
  text_area
  textarea
  text_field
  time_field
  time_zone_select
  trix_editor
  url_field
  week_field
)

Instance Method Summary collapse

Instance Method Details

#form_for(record, options = {}, &block) ⇒ Object

Override form_for to capture original options (Rails 4+). This is the only way to capture data attributes that are provided via string like “data-asp-disabled”.



60
61
62
63
# File 'lib/auto_strong_parameters/auto_form_params.rb', line 60

def form_for(record, options = {}, &block)
  @_asp_original_options = options.dup
  super
end

#form_with(**args, &block) ⇒ Object

Override form_with to capture original options (Rails 5+).



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/auto_strong_parameters/auto_form_params.rb', line 66

def form_with(**args, &block)
  @_asp_original_options = args.dup

  # Rails 8 requires model to be an object or false, not nil
  # If model is nil and url is provided, set model to false for Rails 8 compatibility
  if args[:model].nil? && args[:url]
    args[:model] = false
  end

  super(**args, &block)
end