Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set only hour in datetime field using simple_form?

I would like to pick an hour(10, 11, 12, 13, 14, 15) from select_box and date from 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
like image 513
tomekfranek Avatar asked Oct 20 '22 21:10

tomekfranek


1 Answers

Maybe this? (I'm not sure about the syntax for the :call_at select box)

# 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)
like image 54
MrYoshiji Avatar answered Nov 01 '22 15:11

MrYoshiji