Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to add leading zeros to the day and month in rails' date_select and datetime_select?
    primarykey
    data
    text
    <p>I'm trying to add leading zeros to the days and months in a date_select, and for all I can see in the docs you can only specify <code>:use_month_numbers</code> and <code>:use_short_month</code> but not <code>:leading_zeros =&gt; true</code>.</p> <p>Looking at the rails code, I found that the following code in date_helper.rb: </p> <p>File: <a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/date_helper.rb" rel="nofollow">actionpack/lib/action_view/helpers/date_helper.rb</a></p> <pre><code>def select_day if @options[:use_hidden] || @options[:discard_day] build_hidden(:day, day) else build_options_and_select(:day, day, :start =&gt; 1, :end =&gt; 31, :leading_zeros =&gt; false) end end </code></pre> <p>And in line 856 under DateTimeSelector, there's a line that goes:</p> <pre><code>leading_zeros = options.delete(:leading_zeros) </code></pre> <p>So I get the impression that even if you managed to override the first method, and called <code>DateTimeSelector</code> with <code>leading_zeros =&gt; true</code>, that it would just end your party there, so it's not possible to do this this way.</p> <p>Now, my ruby-fu / rails-fu is not that legendary so I was wondering – could I override the class in my rails app reimplementing only the method(s) I want in order to support leading_zeros, or what would be the best way way to get this to work?</p> <p>EDIT: In case someone's asking <em>why does he even need leading zeroes?</em>, well, it's not a deal breaker, and it's not <em>necessary</em>, but I would like to be able to do this… just for consistency across the app. The dates are displayed with a dd/mm/yy format across app and in reports, but when creating the records the user finds a different format. It's not so important, just a design choice.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload