From 3a2fa07ecc1d33daf5ae0e8812eb982d8fc822aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Villeneuve?= Date: Thu, 7 Mar 2024 11:39:35 +0100 Subject: [PATCH] Fix encrypted attributes improperly casted --- lib/simple_form/form_builder.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index a5cb4c14..875960fc 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -599,7 +599,11 @@ def file_method?(attribute_name) 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