0

会社、顧客、管理者の 3 つのユーザー カテゴリを持つアプリケーションに、Rails 3.2、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 を呼び出していません。

何か案は?

4

1 に答える 1

3

CanCan は、アプリケーションについて 2 つの想定を行います。

  • 権限を定義する能力クラスがあります。
  • 現在のユーザーモデルを返すコントローラーに current_user メソッドがあります。

ApplicationController で current_ability メソッドを定義することにより、これらの両方をオーバーライドできます。

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

于 2013-03-16T14:19:08.563 に答える