lib/action_view/helpers/date_helper.rb
# Build select option html from date value and options.
#  build_options(15, :start => 1, :end => 31)
#  => "<option value="1">1</option>
#      <option value="2">2</option>
#      <option value="3">3</option>..."
#
# If <tt>:step</tt> options is passed
#  build_options(15, :start => 1, :end => 31, :step => 2)
#  => "<option value="1">1</option>
#      <option value="3">3</option>
#      <option value="5">5</option>..."
Build select option html from date value and options.


Build select option html from date value and options .
def build_options(selected, options = {})
          start         = options.delete(:start) || 0
          stop          = options.delete(:end) || 59
          step          = options.delete(:step) || 1
          options.reverse_merge!({:leading_zeros => true, :ampm => false})
          leading_zeros = options.delete(:leading_zeros)
          select_options = []
          start.step(stop, step) do |i|
            value = leading_zeros ? sprintf("%02d", i) : i
            tag_options = { :value => value }
            tag_options[:selected] = "selected" if selected == i
            text = options[:ampm] ? AMPM_TRANSLATION[i] : value
            select_options << content_tag(:option, text, tag_options)
          end
          (select_options.join("\n") + "\n").html_safe
        end
def build_options ( selected , options = { } ) start = options . delete ( :start ) || 0 stop = options . delete ( :end ) || 59 step = options . delete ( :step ) || 1 options . reverse_merge! ( { :leading_zeros => true , :ampm => false } ) leading_zeros = options . delete ( :leading_zeros ) select_options = [ ] start . step ( stop , step ) do | i | value = leading_zeros ? sprintf ( "%02d" , i ) : i tag_options = { :value => value } tag_options [ :selected ] = "selected" if selected == i text = options [ :ampm ] ? AMPM_TRANSLATION [ i ] : value select_options << content_tag ( :option , text , tag_options ) end ( select_options . join ( "\n" ) + "\n" ) . html_safe end
Build select option html from date value and options.
Build select option html from date value and options .
selected
options