Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 如何设置简单表单时间输入的默认时间_Ruby On Rails 3_Simple Form - Fatal编程技术网

Ruby on rails 3 如何设置简单表单时间输入的默认时间

Ruby on rails 3 如何设置简单表单时间输入的默认时间,ruby-on-rails-3,simple-form,Ruby On Rails 3,Simple Form,我有以下简单的表单输入(HAML): as::time部分可能是多余的,因为数据库列类型是time,我认为simple_form可以检测到它 它默认为当前时间(显示两个选项,一个为小时,另一个为分钟)。我无法使用默认值或值设置00:00的默认值。这可能吗 我无法在简单表单代码库中找到此默认设置的位置。任何帮助都将不胜感激 我还没有发现可以使用简单表单的时间选择器。我可以使用默认选项: = congress_detail_form.input :stand_setup_time, as: :tim

我有以下简单的表单输入(HAML):

as::time部分可能是多余的,因为数据库列类型是time,我认为simple_form可以检测到它

它默认为当前时间(显示两个选项,一个为小时,另一个为分钟)。我无法使用默认值或值设置00:00的默认值。这可能吗

我无法在简单表单代码库中找到此默认设置的位置。任何帮助都将不胜感激


我还没有发现可以使用简单表单的时间选择器。

我可以使用默认选项:

= congress_detail_form.input :stand_setup_time, as: :time, default: Time.parse('8:00')

我想说您在控制器中为实例变量设置默认值

假设您从
CongressesController
渲染视图:

class CongressesController < ApplicationController
  ...
  def new
    @congress_detail = CongressDetail.new(stand_setup_time: Time.parse('00:00'))
  end
  ...
end
类一致性控制器

它可以让您的视图更小、更清晰。这就是您应该如何保持它们=)

是的,默认值:有效,但对于这种数据库列类型,as::time是多余的。
class CongressesController < ApplicationController
  ...
  def new
    @congress_detail = CongressDetail.new(stand_setup_time: Time.parse('00:00'))
  end
  ...
end