gpt4 book ai didi

ruby-on-rails - 如何使用 simple_form 在日期时间字段中仅设置小时?

转载 作者:数据小太阳 更新时间:2023-10-29 07:17:48 26 4
gpt4 key购买 nike

我想从 select_box 中选择一个 hour(10, 11, 12, 13, 14, 15) 并从 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

最佳答案

也许是这个? (我不确定 :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)

关于ruby-on-rails - 如何使用 simple_form 在日期时间字段中仅设置小时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19790409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com