I have an ActiveRecord model Eventwith a datetime column starts_at. I would like to present a form, where date and time for starts_at
Elegant solution may provide date_time_attribute gem:
class MyModel < ActiveRecord::Base
include DateTimeAttribute
date_time_attribute :starts_at
end
It will allow you to set starts_at_date and starts_at_time separately:
form_for @event do |f|
f.text_field :starts_at_date
f.text_field :starts_at_time
f.submit
end
# this will work too:
form_for @event do |f|
f.date_select :starts_at_date
f.time_select :starts_at_time, :ignore_date => true
f.text_field :starts_at_time_zone
f.submit
end
# or
form_for @event do |f|
f.date_select :starts_at_date
f.text_field :starts_at_time
f.submit
end
It will also allow you to play with time zones, use Chronic etc.