From d8eb374c120c21884a827e01ec9975dec97da702 Mon Sep 17 00:00:00 2001 From: Drew Ulmer Date: Thu, 17 Aug 2023 17:28:06 -0500 Subject: [PATCH] Add support for radio buttons --- TODO.md | 1 - lib/auto_strong_parameters/auto_form_params.rb | 7 +------ test/apps/basic_controller.rb | 2 ++ test/apps/user.rb | 2 +- test/auto_form_params_test.rb | 1 + 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 012a69b..0974022 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,6 @@ - [X] Add a hidden field with a signed string of all the fields used in the form builder - [X] Look at how cookies are decrypted to decrypt server-side - [X] Patch ActionController::Parameters to have auto_permit! and use the shape from the form -- [ ] Add radio button support - [ ] Handle signature verification errors in a customizable way (error/log/silent) - [ ] For upgrades, we can suggest / allow a setting to try to catch the exception that SP raises and try to call auto_permit! and don't raise. - [ ] Support SimpleForm / other form builders diff --git a/lib/auto_strong_parameters/auto_form_params.rb b/lib/auto_strong_parameters/auto_form_params.rb index b79a624..70f45c1 100644 --- a/lib/auto_strong_parameters/auto_form_params.rb +++ b/lib/auto_strong_parameters/auto_form_params.rb @@ -13,7 +13,7 @@ module AutoStrongParameters::AutoFormParams TRACKED_FIELDS = %w( search_field telephone_field date_field time_field datetime_field month_field week_field url_field email_field number_field range_field - file_field password_field text_area text_field + file_field password_field text_area text_field radio_button ) TRACKED_FIELDS.each do |name| @@ -26,11 +26,6 @@ def #{name}(*args) RUBY_EVAL end - # TODO - def radio_button(*) - super - end - private def _asp_track_field(field) diff --git a/test/apps/basic_controller.rb b/test/apps/basic_controller.rb index 904601d..5ecf708 100644 --- a/test/apps/basic_controller.rb +++ b/test/apps/basic_controller.rb @@ -17,6 +17,8 @@ class BasicController < ActionController::Base <%= f.number_field :age %> <%= f.range_field :years_of_experience %> <%= f.password_field :password %> + <%= f.radio_button :preferred_phone_os, :iphone %> + <%= f.radio_button :preferred_phone_os, :android %> <%= f.fields_for :parents do |parf| %> <%= parf.text_field :name %> <%= parf.text_area :job %> diff --git a/test/apps/user.rb b/test/apps/user.rb index bf0258a..ddd5f4f 100644 --- a/test/apps/user.rb +++ b/test/apps/user.rb @@ -3,7 +3,7 @@ class User attr_accessor :name, :email, :description, :phone, :dob, :lunch_time, :confirmed_at, :birth_month, :birthday_week, :favorite_url, :age, - :years_of_experience, :password + :years_of_experience, :password, :preferred_phone_os def parents @parents ||= [Parent.new] diff --git a/test/auto_form_params_test.rb b/test/auto_form_params_test.rb index 9427d68..5f4956a 100644 --- a/test/auto_form_params_test.rb +++ b/test/auto_form_params_test.rb @@ -27,6 +27,7 @@ def permitted_keys "age", "years_of_experience", "password", + "preferred_phone_os", { "parents_attributes"=>[ "name",