Skip to content

Commit

Permalink
Merge pull request #1836 from Michaelvilleneuve/fix_encrypted_attribu…
Browse files Browse the repository at this point in the history
…tes_improperly_casted

Fix encrypted attributes improperly casted
  • Loading branch information
nashby authored Jul 12, 2024
2 parents 4c43a75 + 3a2fa07 commit c2c7faf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/simple_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2c7faf

Please sign in to comment.