Last active
September 10, 2015 06:50
-
-
Save ivalentinee/9b48dcd946232a2fcebb to your computer and use it in GitHub Desktop.
MoneyRails user input workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaymentInput < SimpleForm::Inputs::Base | |
def input(wrapper_options) | |
custom_input_options = { value: value, maxlength: 16 } | |
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) | |
merged_input_options = merge_wrapper_options(custom_input_options, merged_input_options) | |
@builder.text_field(attribute_name, merged_input_options) | |
end | |
def value | |
before_type_cast_value = object.send("#{attribute_name}_money_before_type_cast") | |
current_value = object.send(attribute_name) | |
humanized_current_value = template.humanized_money(current_value) | |
before_type_cast_value || humanized_current_value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem here is that
before_type_cast_value
is always filled, even if value is correctly set from a float, meaning the output does not humanize the input in this case.example: