Concatenate multiple drop down values into a single string

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 CalendarHelper

    def 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)
    end

    private
    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

Hey guys,
I need a hand - no-one’s run into this before?

kodama

Why not just use time_select?

On Dec 10, 2007 12:50 PM, Old E. [email protected]
wrote:

Hey guys,
I need a hand - no-one’s run into this before?

kodama

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net

I checked it out, but I don’t like how the hours go from 0 to 23. Also,
I need to have the time select show up as [hour][min][am|pm].

Do you know what I’m doing wrong in my widget?

Ryan B. wrote:

Why not just use time_select?

On Dec 10, 2007 12:50 PM, Old E. [email protected]
wrote:

Hey guys,
I need a hand - no-one’s run into this before?

kodama

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs