2012-09-21 32 views
0

我想爲乳腺癌意識月份(十月)使用不同的徽標......我還希望使用參數測試徽標,以便確保它可以正常工作直到十月之前鼻菸。明顯做錯了什麼!紅寶石檢查是否是十月份顯示粉紅色標誌

控制器:

def breast_cancer_logo_month 
    if params[:breast_cancer_logo_month] || Time.current.month = 10 
    return true 
    end 
    false 
end 

觀點:

<% if breast_cancer_logo_month %> 
    #breast cancer logo 
<% else %> 
    #standard logo 
<% end %> 
+0

變化'Time.current.month = 10'到'Time.current.month == 10' – Salil

回答

4

你breast_cancer_logo_month是錯誤的。當你需要兩個時,你正在使用一個簡單的平等。其中一個等於會嘗試覆蓋Time.current.month值,這會引發錯誤。
如果您在條件中返回true或false,則可以僅返回條件。你可以添加一個?也是方法名稱。

def breast_cancer_logo_month? 
    !!params[:breast_cancer_logo_month] || Time.current.month == 10 
end 

<% if breast_cancer_logo_month? %> 
    #breast cancer logo 
<% else %> 
    #standard logo 
<% end %> 
+0

感謝您的快速重新!!!!該方法進入控制器嗎?獲取未定義的方法'breast_cancer_logo_month?' – jahrichie

+0

GOT IT!必須將其添加爲helper_method:breast_cancer_logo_month? – jahrichie

+0

你的'breast_cancer_logo_month?'應該在助手,而不是控制器。 – oldergod