0

I am trying to create a time_select in a rails3 application which only allows '15' and '45' to be chosen.

I am already using :minute_step => 30, but that only gives me 0,30. I guess I am looking for an option :minute_offset => 15, which doesn't seem to exist...

ChrisDekker
  • 1,584
  • 18
  • 39

1 Answers1

0

Creating my own FormBuilder turned out to be too cumbersome for one simple extension I wanted to add.

Turns out the minute_select function already has a start (offset) parameter which is defaulted to 0. Simply passing an extra argument down fixed the issue. (minute_offset is the new option here)

ActionView::Helpers::DateTimeSelector.class_eval do
  def select_minute
    if @options[:use_hidden] || @options[:discard_minute]
      build_hidden(:minute, min)
    else
      build_options_and_select(:minute, min, :step => @options[:minute_step], :start => (@options[:minute_offset] || 0) % (@options[:minute_step] || 60))
    end
  end
end

I am taking suggestions on how to do this more cleanly as opposed to this global monkey patching

ChrisDekker
  • 1,584
  • 18
  • 39