2016-06-08 89 views
0

我有一個列表交易時間存儲在我的數據庫中,並選擇在工作日使用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 
+0

'hours_fields.weekday'中有什麼值? –

+0

0,1,2,3,4,5,6其中每個int表示星期幾 –

+0

你應該有什麼工作 –

回答

0

你有兩個=在同一行。套住DAYNAMES系列。

= hours_fields.label 
    = Date::DAYNAMES[hours_fields.weekday] 
相關問題