2016-05-12 71 views
0

我正在使用設計並設置了幫助器方法來檢查是否有任何類型的用戶登錄。我有玩家和教練用戶類型,current_player和current_coach是設計存在的方法。檢查是否有任何類型的用戶登錄

這裏是我的application_controller:

helper_method :current_account, :account_signed_in? 

def current_account 
    if @current_player 
    @current_account = current_player 
    elsif @current_coach 
    @current_account = current_coach 
    end 
end 

def account_signed_in? 
    current_account != nil 
end 

的球員和教練車型是用戶模型的子模型。

class Player < User 
end 
class Coach < User 
end 

此作品(但前提是current_player):

def current_account 
@current_account = current_player 
end 

如果我刪除從current_player和current_coach的@我得到一個錯誤:

wrong number of arguments (given 10, expected 2) 

回答

0

current_account住宿零因爲你的條件和你的elsif條件都不是真的。這意味着@current_player@current_coach是零(或假)

+0

current_player(不帶@)不是零,但在if語句我得到一個錯誤「錯誤的參數數目(10給出,預計2)」如果我刪除@ – user2759575

+0

向我們展示更多代碼:current_player和current_coach從哪裏來? – Fred

+0

他們來自設計。我使用sti,玩家和教練是用戶模型的子模型。 – user2759575