[英]Storing Time_Select in Array Rails
我正在遍歷一系列工作日(星期日)。 我想每天在一個單獨的數組中保存時間,該數組稱為delivery_times
:
意見/命令/ _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
,但它不存在。 如何將時間存儲到數組中?
您可以使用ActionView
time_tag
, 文檔
<%= f.time_field :time, "delivery_times" => :time %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.