Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.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 如何在编辑表单的文本字段中填写时间?_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 如何在编辑表单的文本字段中填写时间?

Ruby on rails 如何在编辑表单的文本字段中填写时间?,ruby-on-rails,ruby,Ruby On Rails,Ruby,在迁移中: t.time :time_from =>在postgress中,来自列的时间类型为:不带时区的时间 添加新数据时: =>time\u from=08:00:00 当我进入编辑时: @post = Post.find([params[:id]]) 形式: 但我只想显示时间=>08:00 我试过这样做,但不起作用 @post = Post.find([params[:id]]) @post.time_from = Time.parse(@post.time_from.strftim

在迁移中:

t.time :time_from
=>在postgress中,来自列的时间类型为:不带时区的时间

添加新数据时: =>time\u from=08:00:00

当我进入编辑时:

@post = Post.find([params[:id]])
形式:

但我只想显示时间=>08:00 我试过这样做,但不起作用

@post = Post.find([params[:id]])
@post.time_from = Time.parse(@post.time_from.strftime("%I:%M%p"))

我该怎么做

如果您想使用strftime,只需使用“%I:%M”:

或者您也可以使用
来添加
:time

@post.time_from.to_s(:time)


Date、DateTime和Time
to\s
方法是的别名。

谢谢Sebastian Palma!
@post.time_from.to_s(:time)