如何为当前月份的属性创建条件?

时间:2016-09-05 11:12:22

标签: ruby-on-rails ruby

如果针对当前月份设置了<b>September</b>deadline的质询,如何才显示t.date "deadline"

控制器

@challenges = current_user.challenges.unaccomplished.order("deadline ASC").select{ |challenge| challenge.deadline.month == Date.current.month }
@current_month = (@challenges).group_by { |t| [t.deadline.year, t.deadline.month] }

查看

<% if @current_month[Date.current.month].present? %> # This is not currently being triggered even though their is a challenge with a deadline in the current month.
  <b>September</b>
<% end %>

1 个答案:

答案 0 :(得分:2)

您已将组密钥定义为元组[年,月]。 当您从列表中挑选挑战时,您需要使用完全相同的格式。即。

@current_month[[Date.current.year, Date.current.month]]