2016-09-05 61 views
0

如何才能顯示<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 %> 

回答

2

您已經定義了組密鑰的元組[年,月]。 當您從列表中挑選挑戰時,您需要使用完全相同的格式。即

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

經過數小時的努力,我感到非常親密!謝謝 :) –

相關問題