如何使用simple_form在datetime字段中仅设置小时?

时间:2013-11-05 13:42:39

标签: ruby-on-rails ruby datetime simple-form

我想从hour(10, 11, 12, 13, 14, 15)中选择select_box并从params[:call_date]

中选择日期
# params[:call_date] => "2013-11-05"
= simple_form_for @welcome_call do |f|
  = f.input :call_at, as: :datetime
  = f.association :user, collection: User.all
  = f.submit

1 个答案:

答案 0 :(得分:3)

也许这个? (我不确定:call_at选择框的语法)

# params[:call_date] => "2013-11-05"
= simple_form_for @welcome_call do |f|
  = f.input :call_at, as: :select, collection: (10..15)
  = f.association :user, collection: User.all
  = f.submit

# in controller:
date = Date.parse(params[:call_date])
date_time = DateTime.new(date.year, date.month, date.mday, params[:call_at].to_f, 0)