Nick
Nick

Reputation: 2805

cant get cancan to work on rails 3.1

I had a two month break using Rails and now its biting me when I return!

I am trying to get CanCan to work on Rails 3.1 and have viewed the railscast and then followed their instructions on the cancan git page. However when I try run the homepage it gives me the following error:

Routing Error

undefined local variable or method `authorize_resource' for StaticController:Class

How do I make this stop? Its as if cancan is not loaded, but I have installed it using bundler and it doesnt mention that I have to do anything else to include it.

Anyone have any ideas?

Upvotes: 0

Views: 476

Answers (1)

Nick
Nick

Reputation: 2805

Sorry my bad! Too much coffee resulted in me not reading all the instructions for how to install it.

I needed to add the following to my ApplicationController:

  def current_ability
    @current_ability ||= Ability.new(current_user)
  end

and then I needed to use

class StaticController < ApplicationController
  authorize_resource :class => false

Because in this particular example it was just a static simple homepage that sits infront of a more complicated web app.

Thanks for the help.

Upvotes: 1

Related Questions