根据存储在数据库中的int显示星期几

时间:2016-06-08 12:45:08

标签: ruby-on-rails date haml dayofweek fields-for

我有一个存储在我的数据库中的交易时间列表,并选择在工作日使用int。我现在正试图循环代码,以便能够显示一个表单,允许用户更新给定日期的交易时间,虽然我无法获得一周中某一天的int显示为字符串< / p>

= form.fields_for :trading_hours do |hours_fields|
  %li.mdl-list__item.mdl-list__item--two-line
    %span.mdl-list__item-primary-content
      = hours_fields.label= Date::DAYNAMES[hours_fields.weekday]
      %span.mdl-list__item-sub-title
        = hours_fields.time_select :open_time, {:default => {:hour => '9', :minute => '00'}, :minute_step => 15, :ampm => true}
        \-
        = hours_fields.time_select :close_time, {:default => {:hour => '17', :minute => '00'}, :minute_step => 15, :ampm => true}
    %span.mdl-list__item-secondary-action
      %label.mdl-checkbox.mdl-js-checkbox.mdl-js-ripple-effect{:for => hours_fields}
        = hours_fields.check_box :trades, :class => 'mdl-checkbox__input', :id => hours_fields

交易时间模型

class TradingHour < ActiveRecord::Base
  belongs_to :merchant

  scope :open_now, -> (day, time) do
    where('weekday = ? AND open_time <= ? AND close_time > ?', day, time, time)
  end
end

1 个答案:

答案 0 :(得分:0)

您在同一行上有两个=。嵌套DAYNAMES系列。

= hours_fields.label
  = Date::DAYNAMES[hours_fields.weekday]