Last active
December 2, 2024 12:37
-
-
Save coolprobn/36c4cfd3a78e3f1b150d6eaf8e4ae2e0 to your computer and use it in GitHub Desktop.
Test view helper methods without having to render the whole view in Rails using rails console
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
# E.g. You have this code to format float values in your view | |
module ApplicationHelper | |
def format_number(value, precision: 4) | |
number_with_precision(value, precision:, strip_insignificant_zeros: true, delimiter: ',') | |
end | |
end | |
# You can test the method format_number() using `helper.method_name` in rails console | |
$ rails c | |
=> helper.format_number(120.0019) | |
#=> 120.0019 | |
=> helper.format_number(9000.0300) | |
#=> 9,000.03 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment