From 2f101559fbdf94110185deaa6a08bf6dc7805165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Villeneuve?= Date: Thu, 7 Mar 2024 12:01:13 +0100 Subject: [PATCH 1/2] fix: monkey patch simple form to fix NIR input --- .../initializers/monkey_patch_simple_form.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 config/initializers/monkey_patch_simple_form.rb diff --git a/config/initializers/monkey_patch_simple_form.rb b/config/initializers/monkey_patch_simple_form.rb new file mode 100644 index 000000000..d66283bec --- /dev/null +++ b/config/initializers/monkey_patch_simple_form.rb @@ -0,0 +1,18 @@ +module SimpleFormEncryptedAttributesExtension + private + + def find_attribute_column(attribute_name) + if @object.respond_to?(:type_for_attribute) && @object.has_attribute?(attribute_name) + @object.type_for_attribute(attribute_name.to_s) + detected_type = @object.type_for_attribute(attribute_name.to_s) + + # Some attributes like ActiveRecord::Encryption::EncryptedAttribute are detected + # as different type, in that case we need to use the original type + detected_type.respond_to?(:cast_type) ? detected_type.cast_type : detected_type + elsif @object.respond_to?(:column_for_attribute) && @object.has_attribute?(attribute_name) + @object.column_for_attribute(attribute_name) + end + end +end + +SimpleForm::FormBuilder.prepend(SimpleFormEncryptedAttributesExtension) \ No newline at end of file From 3d38ed916bf176c532b8e2576a8e385b09124946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Villeneuve?= Date: Thu, 7 Mar 2024 12:07:30 +0100 Subject: [PATCH 2/2] fix: linter --- config/initializers/monkey_patch_simple_form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/monkey_patch_simple_form.rb b/config/initializers/monkey_patch_simple_form.rb index d66283bec..892f78bdf 100644 --- a/config/initializers/monkey_patch_simple_form.rb +++ b/config/initializers/monkey_patch_simple_form.rb @@ -15,4 +15,4 @@ def find_attribute_column(attribute_name) end end -SimpleForm::FormBuilder.prepend(SimpleFormEncryptedAttributesExtension) \ No newline at end of file +SimpleForm::FormBuilder.prepend(SimpleFormEncryptedAttributesExtension)