我正在循环一系列工作日(太阳星期一)。我想在一个名为delivery_times
的单独数组中保存每一天的时间:
views / orders / _form.html.erb
<% Date::DAYNAMES.each_with_index do |day, index| %>
<div class="field">
<%= day %><br>
<%= check_box_tag "delivery_days[]", index %>
</div>
<div class="field">
<%= f.label :time %><br>
<%= f.time_select :time, "delivery_times[]" => :time %>
</div>
<% end %>
控制器
def create
@times = params[:delivery_times]
params[:delivery_days].each do |day, time|
@order = Order.create(order_params.merge( {:day => day}, {:time => @times[index]} ))
end
redirect_to @order, notice: 'Order was successfully created.'
end
目前delivery_days
已正确保存,但delivery_times
无法保存时间。我尝试找time_select_tag
,但它不存在。如何将时间存储到数组中?
答案 0 :(得分:1)
您可以使用ActionView
time_tag
,docs
<%= f.time_field :time, "delivery_times" => :time %>