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
Prefix option for number_to_human_size #327
Conversation
In which cases is useful to display a wrong information? :) |
This version is fine by me. Some people might want the third option (binary with the correct prefix) but in our application we're only using the SI version. |
@josevalim Mac OS X e Ubuntu, for example, are operating systems that use the SI prefix. As today, if you choose to upload to a Rails application a 1 MB file and then you format the number of bytes in the server to display it back to the user, the result will not be 1 MB. |
touchez. applied! |
Prefix option for number_to_human_size
@@ -304,6 +304,7 @@ module ActionView | |||
# * <tt>:separator</tt> - Sets the separator between the fractional and integer digits (defaults to "."). | |||
# * <tt>:delimiter</tt> - Sets the thousands delimiter (defaults to ""). | |||
# * <tt>:strip_insignificant_zeros</tt> - If +true+ removes insignificant zeros after the decimal separator (defaults to +true+) | |||
# * <tt>:prefix</tt> - If +:si+ formats the number using the SI prefix (defaults to :binary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the default specified as :binary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 346. If :prefix is different than :si, the binary base will be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. But then there is no :binary
symbol involved here, right? I can give any value to :prefix to get the binary behavior(1024).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because as the relative base will not be found, the default will be used.
As @trejkaz mentioned, in some cases it's useful to use the SI prefix when formatting bytes. I understand why this is not the default, but the related patch added a :prefix option to number_to_human_size so the developer can choose what to display in each scenario.