2017-02-10 41 views
0

我想顯示的用戶名只在平日,我的看法是這樣的工作日:顯示用戶名只在軌

= calendar @date do |date| 
    = date.day 
    - @leaves.each do |leave| 
     - if (leave.from_date..leave.to_date).include? date 
     %p.name= link_to leave.user.name, leave 

我使用full_calendar寶石。但它在星期六和星期日也顯示用戶的名字。所以,我想在週末限制顯示用戶名。任何人都可以幫我嗎?

回答

0

您可以進行以下檢查日期。

today = Date.today 
if !(today.saturday? || today.sunday) 
display user 
end 
2

如果條件如下,您可以更新:

- if !date.saturday? && !date.sunday? && date.in?(leave.from_date..leave.to_date) 

一個清潔的方法是添加一個方法Date類:

class Date 
    def weekend? 
    saturday? || sunday? 
    end 

    def weekday? 
    !weekend? 
    end 
end 

然後

- if date.weekday? && date.in?(leave.from_date..leave.to_date) 
+0

添加後 - if!date.saturday? &&!date.sunday? && date.in? 這是拋出語法錯誤。 –

+0

你能發佈錯誤嗎? –

+0

我得到了答案,謝謝。 –