Hello Rails board,
I’ve been poking around the documentation, but I can’t seem to find what
I’m looking for. Also, all the code below is the standard scaffold stuff
(besides my helper method).
Basically, my problem is this: I have a string field on my “Event” model
which is called “start_time”. I tried using a datetime data type, but I
don’t like the time select widgets that Rails provides. Basically, the
widget I need is [hour][min][am|pm].
I tried rolling my own multiselect, and I got it to show up in the UI
the way I wantedm but the problem I’m having is that only value from the
first drop-down (i.e. the hour) is getting saved to the database. I
realize that I’m missing a step here somewhere, so I’m hoping someone
could point me in the right direction. Thank you!
For reference, here is what I tried to use:
- View (from _form.rhtml) -
Start time
<%= my_time_select 'event', 'start_time' %>
-
My Helper Method -
module CalendarHelperdef my_time_select(object, method)
#Hour, minutes, ampm
select(object, method, hour_opts, :include_blank => true, :selected
=> nil) +
select(object, method, %w{00 15 30 45}, :include_blank => true,
:selected => nil) +
select(object, method, %w{am pm}, :include_blank => true,
:selected => nil)
endprivate
def hour_opts
hours = []
1.upto(12) {|hour| hours << hour}
return hours
end
end
- The create() method that is getting called -
@event = Event.new(params[:event])
So…what am I missing? I’m guessing the problem is with my create
method in the controller. Thanks all!
-kodama