【发布时间】:2016-06-08 12:45:08
【问题描述】:
我的数据库中存储了一个交易时间列表,并选择在工作日使用 int。我现在正在尝试遍历代码,以便能够显示一个表单,该表单将允许用户更新给定日期的交易时间,尽管我无法将一周中某一天的 int 显示为字符串
= 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
【问题讨论】:
-
hours_fields.weekday中有哪些值? -
0,1,2,3,4,5,6 其中每个 int 代表一周中的一天
-
你所拥有的应该工作
-
我得到了
undefined methodweekday' #<:helpers::formbuilder:0x007f9c4fad2ee0>` -
你能把你的
TradingHours模型贴出来吗
标签: ruby-on-rails date haml dayofweek fields-for