2012-09-27 20 views
0

我在通過helper訪問我的單元格視圖中的Cookie對象時遇到問題。我的代碼如下所示:帶單元和助手的滑軌

#cell 
helper SessionsHelper 

#cell view 
signed_in? 

#sessions helper 
signed_in? 
    cookies.sth 
end 

我收到錯誤:undefined local variable or method cookies'`。

如何讓cookie在那裏可見?

或者,我想將Helper作爲對象協作者傳遞給我的單元格,因爲此輔助程序包含許多有用的方法。正在做SessionHelper.new正確的方法來做到這一點?

<%= render_cell :my_cell, :display, session_helper: SessionsHelper.new %> 

我現在看到SessionsHelper實際上是一個模塊,所以我不能調用new()方法。我應該如何處理未定義的cookies?

回答

0

我總是在ApplicationController中定義signed_in?。 (有cookies適用)然後做:

helper_method :signed_in? 

,使其可以作爲一個輔助方法。

至於你的第二個問題:session_helper: SessionsHelper.new是沒有必要的。 全部方法從全部幫手可用全部意見。