0
votes

I am using Rails 3.2, Devise and Cancan for an application with 3 user categories: Companies, Customers and Admins.

My problem is that I get this:

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

In HomeController I have:

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

  def index
        render 'index'
    end

end

Also, in the view:

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

I am not calling current_user anywhere in my code.

Any ideas?

1
What does your "authenticate_customer!" method look like? - cpuguy83
It's from devise, I didn't implement it. - cgf
Are you using CanCan or some other gem that interacts with Devise? I mention CanCan specifically because you may have to create a current_ability method in your ApplicationController, per this GitHub issue. - Jim Stewart
Note that in general, anywhere that current_user is referenced will need to be changed to current_customer, but you say you're not referencing current_user anywhere. - Jim Stewart

1 Answers

3
votes

CanCan makes two assumptions about your application.

  • You have an Ability class which defines the permissions.
  • You have a current_user method in the controller which returns the current user model.

You can override both of these by defining the current_ability method in your ApplicationController.

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