Rails select_date form name
As much as I love rails, I've always hated dealing with da开发者_高级运维tes 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)
精彩评论