我已经使用帮助器显示假日和树叶的背景颜色,并且我从这个视图中调用辅助方法 -
%th{:class => weekend_class_top(date)}= date.strftime("%d")
已被调用的辅助方法 -
def weekend_class_top(date)
if (date == date.end_of_month)
'weekend_color5'
elsif (date.to_s(:weekend) == 'Sun')
'weekend_color3'
elsif @holidays.any?
@holidays.map.each do |holiday|
if (date == holiday)
'timesheet_holiday_color'
end
end
elsif @user_leaves.any?
@user_leaves.flatten.map.each do |leave|
if (date == leave)
'timesheet_leave_color'
end
end
end
end
我写过的代码,即使节假日和假期都存在,我也只能在假期时获得背景颜色。
这是编辑好的辅助方法 -
def weekend_class_top(date)
if (date == date.end_of_month)
'weekend_color5'
elsif (date.to_s(:weekend) == 'Sun')
'weekend_color3'
elsif @holidays.any?
@holidays.map.each do |holiday|
if @user_leaves.any?
@user_leaves.flatten.map.each do |leave|
if (date == leave)
'timesheet_leave_color'
end
end
elsif (date == holiday)
'timesheet_holiday_color'
end
end
end
end
通过上面写的方法,我只获得了叶子的背景颜色,但不是假期。
答案 0 :(得分:0)
这就是我得到正确结果的方法 -
def weekend_class_top(date)
if (date == date.end_of_month)
'weekend_color5'
elsif (date.to_s(:weekend) == 'Sun')
'weekend_color3'
elsif @holidays.include?(date)
'timesheet_holiday_color'
elsif @user_leaves.flatten.include?(date)
'timesheet_leave_color'
end
end