【发布时间】:2019-11-17 10:12:24
【问题描述】:
我正在尝试以一种不错的方式输出时间。 这是我的新代码
<%= form_for @reservation do |f| %>
<span><label>Pick up time</label></span>
<%= f.time_select :time,ampm: true, class: "textbox"%></span>
<% end %>
这是在输出文件中
<strong>Pick up Time:</strong> <%= @reservation.time.strftime("%H:%M") %>
我收到了这个错误 “{1=>2019, 2=>7, 3=>7, 4=>16, 5=>0}”的未定义方法`strftime':字符串 你的意思是?剥离
请有人帮我解决这个问题
【问题讨论】:
-
@reservation.time返回什么? -
{1=>2019, 2=>7, 3=>7, 4=>19, 5=>59}
-
这看起来像一个哈希。
strftime是一个 DateTime 方法,如果有的话,您的架构中保留时间的数据类型是什么? -
add_column :reservations, :time, :string
标签: html ruby-on-rails forms strftime