在阵列导轨中存储Time_Select

时间:2015-09-12 06:59:26

标签: ruby-on-rails ruby

我正在循环一系列工作日(太阳星期一)。我想在一个名为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,但它不存在。如何将时间存储到数组中?

1 个答案:

答案 0 :(得分:1)

您可以使用ActionView time_tagdocs

<%= f.time_field :time, "delivery_times" => :time %>