2013-03-15 113 views
0

我對具有3個用戶類別的應用程序(公司,客戶和管理員)使用Rails 3.2,Devise和Cancan。找不到current_user方法(Rails,Devise,Cancan)

我的問題是,我得到這個:

undefined local variable or method `current_user' for #<HomeController:0xb4fd217c> 

在HomeController中我有:

class HomeController < ApplicationController 
    before_filter :authenticate_customer! 
    load_and_authorize_resource :class => false 

    def index 
     render 'index' 
    end 

end 

而且,在視圖中:

- content_for :title, 'Home' 
= link_to('Logout', destroy_customer_session_path, :method => :delete) 

我不是要求CURRENT_USER任何地方在我的代碼中。

任何想法?

+0

你的「authenticate_customer!」是什麼?方法看起來像? – cpuguy83 2013-03-16 00:49:55

+0

這是從設計,我沒有實現它。 – cgf 2013-03-16 01:06:37

+0

您是使用CanCan還是其他一些與Devise交互的寶石?我特別提到了CanCan,因爲您可能需要根據[此GitHub問題](https://github.com/ryanb/cancan/issues/598)在「ApplicationController」中創建一個'current_ability'方法。 – 2013-03-16 01:15:11

回答

3

CanCan對您的應用程序做了兩個假設。

  • 您有一個能力類定義權限。
  • 在控制器中有一個current_user方法,它返回當前用戶模型。

您可以通過在您的ApplicationController中定義current_ability方法來覆蓋這兩者。

https://github.com/ryanb/cancan/wiki/Changing-Defaults

+0

我會重視一些反饋。我的答案是否解決了您的問題? – cthulhu 2013-03-21 19:24:40

相關問題