dali546
(dali546)
February 23, 2021, 4:04pm
1
I have found numerous times that a date field is nil
. Probably bad code, but still it crops up.
So when i want to use helpers like time_ago_in_words
I have to account for nil cases. Like so.
opened 11:24PM - 17 Oct 14 UTC
closed 06:38AM - 02 Nov 16 UTC
Hello guys,
I would to be able to specify if I want a exception or not when pas… sing a nil value to `I18n.localize` method.
It's a common pattern to do this on rails applications:
``` erb
<%= f.text_field :birthdate, :value => I18n.localize(person.birthdate) %>
```
And the field may or may not have the value (new records doesn't have at all). I thought in something like that:
``` erb
<%= f.text_field :birthdate, :value => I18n.localize(person.birthdate, raise: false) %>
```
It was previously requested on #154 but the idea is to allow the user to specify if the exception is important or not, defaulting to raise on nil.
Wdyt?
I have a proposal to modify rails/date_helper.rb at main · rails/rails · GitHub
to also pass the default
I18n option.
This commit Allow default to be passed · dali546/rails@fd45e8c · GitHub
ghiculescu
(Alex Ghiculescu)
February 24, 2021, 8:05pm
2
Would it make sense to do that on all the methods in DateHelper
?
dali546
(dali546)
February 25, 2021, 8:59am
3
Do you mean all the DateSelector tags too, all the usages of I18n? Yes it would make sense
dali546
(dali546)
March 2, 2021, 2:07pm
4
So shall I just go ahead and make a PR, or do I need approval first?