Kris wrote:
I’m having trouble workign out which ActionView DateHelpers to display a
time input for an ActiveRecord field of type :time.
I just want an hours input and a minuites input. I can get these with
time_select helper using :field_name and :prefix but it gives both hours
and miniutes the same name.
<%= select_time(Time.now, :prefix => “search”, :field_name =>
“start_time”) %>
I see when you use the datetime_select it gives each element something
like 1i, 2i, 3i and 4i, this does not happen with select_time.
The datetime_select would work if I could get rid of the date part,
there is no time_select helper! And I have tried adding the :discard
option but it does not get rid of the year…
<%= datetime_select(“search”, “start_time”, { :discard_year => true,
:discard_month => true, :discard_day => true }) %>
Can anyone clue me in 
Kris.
The select_time helper is not model aware, so you have to do a bit more
work to use it. I just had to deal with this a few days ago, and this is
what I came up with.
You are almost there… drop the :field_name option as that won’t help
you (it changes [hour] and [minute] to [start_time]). Keep the :prefix
option, and set it to the name of the attribute of your model object.
<%= select_time(Time.now, :prefix => “start_time”) %>
Then, when you get to your action, you have to take the params for the
time selection and massage them into params for the model. For a Foo
model, do this:
params[:foo][:start_time] = Time.parse(params[:start_time][:hour] + “:”
- params[:start_time][:minute])
Then you can do the usual foo = Foo.new(params[:foo]) and you’ll get the
start_time as part of the bargain.
If you figure out a better way to handle this, please let me know. My
approach works fine, but it’s not very pretty.
It looks like there is a patch in the works to add a time_select helper
that is model aware, but it hasn’t had much love lately so it might be a
while before it’s ready for use.
–josh
http://blog.hasmanythrough.com