How To Access date_select Without An Active Record Model
Using date_select is great when you’re dumping the returning parameters into an Active Record object, but what if you need to just access them directly, well it gets a little tricky.
View:
<%= date_select('range', 'start_date', :order => [:month, :day, :year])%>
Controller:
@start_date = Date.civil(params[:range][:"start_date(1i)"].to_i,params[:range][:"start_date(2i)"].to_i,params[:range][:"start_date(3i)"].to_i)
You may wonder why I wouldn’t just use select_date. Well there is no option to order the returning select boxes, so I’m stuck with year, month, day. Then use select_month, select_day, select_year, right? Well you only have the option of changing the field_date (:field_date => ’start_year’), and I didn’t really dig that. As you can see, I was creating a range with a start date and an end date, so I wanted that encapsulated… blarg, semantics.
Thank you! This is exactly the problem I had run into. This works like a champ. Thanks!
Comment by Bill — July 24, 2006 @ 1:28 am