Skip to content

Instantly share code, notes, and snippets.

@coolprobn
Last active December 2, 2024 12:37
Show Gist options
  • Save coolprobn/36c4cfd3a78e3f1b150d6eaf8e4ae2e0 to your computer and use it in GitHub Desktop.
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
# 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