Multiple text_field for one variable...

Ok this is probably a silly question, but I've been up all night, and
I'm not thinking right :slight_smile:

Is there a way to have a model's variable set using multiople
text_fields, while still using the

<%= text_field :order, :time %> but have two text_fields for it, and
then

order.create(params[:order]) in the controller...

I know the date_select helper, creates parameters called date(1i),
date(2i), date(3i)... I guess I'm wondering if I can manually do the
same thing, for lets say "time" have a drop down for the hour, and
drop down for the minutes w/o having to then write manual code to set
the time....

I hope that makes sense.

Help!!! Please!!! :frowning:

Yes, you can. If you need to know the details, have a look at the source
code of ActiveRecord::Base#assign_multiparameter_attributes and
following.

Basically, if you have an aggregation defined where the constructor of
the aggregate class takes multiple arguments, you can indicate position
and type of these arguments in parentheses. In this way something(1i),
something(2s), something(3f) are mapped to

  Something.new(
    <fixnum-value-of-param-something(1i)>,
    <string-value-of-param-something(2s)>,
    <float-value-of-param-something(3f)>)

Michael

Forget about aggregations. Yes, it works for them, of course, but the
point is really to supply the multiple arguments needed by the
constructor of a class-valued (i.e. not String, Fixnum and cousins)
attribute.

Michael

Forgot to thank you guys!

I haven't had a chance to test it, I've been fixing some real sloppy
coding... but it makes perfect sense... I'll report back incase somone
else cares :slight_smile: