## SELECT pulldown from a start month to an end month. If the options[:name] is passed a # parameter in the URL, the SELECT will default to the matching OPTION entry. Otherwise, # it will default to the one with the end date. Date string must be parsable by Time.parse().# # options: {# :name, # :start,# :end (optional; defaults to current month)# }## Usage:# <%= select_month :name => 'period', :start => '2008/11' %>#defselect_month(options)
output =""
output.concat"<select name=\"#{options[:name]}\">\n"
dstart =Time.parse(options[:start])
dcurrent = dstart
if options[:end].nil?
dend =Time.nowelse
dend =Time.parse(options[:end])
endwhile dcurrent.strftime('%Y%m').to_i<= dend.strftime('%Y%m').to_ido
period = dend.strftime('%Y_%m')
unless params[options[:name]].nil?
period = params[options[:name]]
end
selected =""if dcurrent.strftime('%Y_%m') == period
selected ="selected=\"selected\""end
output.concat"<option value=\"#{dcurrent.strftime('%Y_%m')}\"#{selected}>"
output.concat dcurrent.strftime('%B %Y')
output.concat"</option>\n"
dcurrent +=1.monthend
output.concat"</select>\n"return output
end