As much as I love rails, I've always hated dealing with dates in an html form...especially when the date isn't an object's property.
The select_date helper is nice, but it always generates this:
<select name="date[year]" id="date_year">
<select name="date[month]" id="date_month">
<select name="date[day]" id="date_day">
And I can't figure out a way to change the name prefix from "date" to something else. Is there a way to do this? What do you all use for date inputs when they're not an object property?
You can use the :prefix option to do this.
<%= select_date(nil, :prefix => 'payday') %>
Which generates this:
<select id="payday_year" name="payday[year]">
<select id="payday_month" name="payday[month]">
<select id="payday_day" name="payday[day]">
More examples here
http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-select_date
if it's not an object property, are you just using the rails date helpers? You can probably do better.
I'd just have a simple textfield, and use jquery to decorate it as a date .. check out this jQuery date drop-down.
You'd then parse it in the controller as a Date and do whatever you need to. it'll just be params[:super_cool_date] (or whatever)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With