仅在rails中的工作日显示用户名

时间:2017-02-10 07:44:09

标签: ruby-on-rails ruby

我想仅在工作日显示用户名,因为我的观点是这样的:

= 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 gem。但它也在周六和周日显示用户名。所以,我想在周末限制显示用户名。有人可以帮帮我吗?

2 个答案:

答案 0 :(得分:2)

您可以按如下方式更新if条件:

- 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)

答案 1 :(得分:0)

您可以在日期进行以下检查。

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