Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(encryption): monkey patch simple form to fix NIR input #1843

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/initializers/monkey_patch_simple_form.rb
Original file line number Diff line number Diff line change
@@ -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)
Loading