Kumar Nikhil
Kumar Nikhil

Reputation: 125

Displaying users name only on week days in rails

I want to display users name only on weekdays for that my views are like this:

= 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

I am using full_calendar gem. but it is displaying name of users on saturday and sunday also. So, I want to restrict displaying users name on weekend. Could anyone please help me?

Upvotes: 0

Views: 61

Answers (2)

Abhishek Kumar
Abhishek Kumar

Reputation: 694

You can update your if condition as follows:

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

A cleaner way would be to add a methods to Date class:

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

  def weekday?
    !weekend?
  end  
end

and then

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

Upvotes: 2

Sapna Jindal
Sapna Jindal

Reputation: 422

You can have the following check on date.

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

Upvotes: 0

Related Questions