Compose data for a column from two fields

I’m working on a datepicker and a timepicker. The datepicker is the
jQuery datepicker. The timepicker displays a drop down menu with
available times.

I want to have two different fields: the datepicker and timepicker. Then
mix up the two (probably in the controller) and come up with the whole
datetime data to be inserted into the database.

The problem is, Rails doesn’t seem to let me create two different
fields.
<%= f.label :start_date %>

<%= f.text_field :start_time %>

I get this error:
Model Appointment does not respond to start_time

And I understand, start_time doesn’t exist in the Model. So how can I
create two fields in the form that don’t exist in the model (kinda like
virtual columns) , then combine their two values and then insert the
result into the database?

Some of you may ask why don’t I just use the jQuery TimePicker, but I
don’t like the time slider and I need to display only available times,
so the jQuery TimePicker is out.

Thanks

Use the _tag versions of the form helpers. i.e., text_field_tag
instead of f.text field.

Leonel . wrote in post #965158:

I’m working on a datepicker and a timepicker. The datepicker is the
jQuery datepicker. The timepicker displays a drop down menu with
available times.

I want to have two different fields: the datepicker and timepicker. Then
mix up the two (probably in the controller) and come up with the whole
datetime data to be inserted into the database.

The problem is, Rails doesn’t seem to let me create two different
fields.
<%= f.label :start_date %>

<%= f.text_field :start_time %>

I get this error:
Model Appointment does not respond to start_time

And I understand, start_time doesn’t exist in the Model. So how can I
create two fields in the form that don’t exist in the model (kinda like
virtual columns) , then combine their two values and then insert the
result into the database?

You’re asking the wrong question. Since you want a virtual attribute on
the model, just create one with attr_accessor.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Leonel, Rails is (rightfully) telling you that those attributes of the
model don’t exist yet. You said, “…then
mix up the two (probably in the controller)…” That’s the part that
is missing. How you do that is through virtual attributes (see
Railscast #16 and #167) and done in the Model, not the Controller. I
don’t think you don’t need to switch over to the _tag helpers for
virtual attributes.

Marnen, “You’re asking the wrong question,” is rarely the right
answer. Thanks for not stopping there.

I was working on that two months ago and I thought I had everything
figured out. But I stopped coding and now that I’m back I can’t remember
what was my plan to do that.

Thanks guys! I’ll try your suggestions.