Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9291449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:38:57+00:00 2026-06-18T20:38:57+00:00

In a Rails 3.2 app I’m using Devise + CanCan. The app previously restricted

  • 0

In a Rails 3.2 app I’m using Devise + CanCan. The app previously restricted access to only logged in users. I’m in the process of adding a Guest user/ability that will be able to read certain sections of the site.

I’m having trouble understanding the “correct” way to set this up, specifically what combination of before_filter :authenticate! and load_and_authorize_resource is needed in controllers.

While working on this I’ve stripped the ability class to a minimum.

#Ability.rb
class Ability
  include CanCan::Ability

  def initialize(user_or_admin)
    user_or_admin ||= User.new

    can :manage, :all
  end
end

In a model-less/ static page Home controller

#home_controller.rb
class HomeController < ApplicationController
  load_and_authorize_resource
  def index
    ...some stuff
  end
end

and

#application_controller.rb
class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :authenticate!
  ...more stuff
end

With this set up, un-logged-in users are redirected to Devise sign in page.

If I remove before_filter :authenticate! from the application controller I get an error uninitialized constant Home from activesupport-3.2.11/lib/active_support/inflector/methods.rb

If I remove load_and_authorize_resource from the home controller, this error goes away.

This is ok with my simplified testing Ability class, but as I start adding roles and abilities back in I will need to have CanCan handling the Home controller, i.e., will need load_and_authorize_resource to be called.

Can anyone help me understand why this error occurs when before_filter :authenticate! is removed, and point me towards any info that explain the “correct” way to set up Devise+Cancan for guest users. The info I’ve found thus far only explains how to set up the Ability class, not how to configure Devise.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:38:58+00:00Added an answer on June 18, 2026 at 8:38 pm

    The problem is that there is no resource to authorize. Therefore, you need only call authorize_resource not load_and_authorize_resource. See authorizing controller actions in the cancan documentation for further information.

    Update: You must also specify the class as false: authorize_resource class: false.

    Then your home controller will look like this:

    class HomeController < ActionController::Base
      authorize_resource class: false
    
      def show
        # automatically calls authorize!(:show, :home)
      end
    end
    

    This information is in the Non-RESTful controllers section. Sorry about that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Rails app /index path should show one page to logged in users, an
My rails app is set up using a mysql database. When I do a
My rails app allows users to edit a certain json file through the browser.
My rails app crashes as soon as I access a web page. My versions
I have a rails app where users have friends list. Now i have to
I have a rails app that gives users assignments and prompts them via email
Our Rails app is using Restful Authentication for user/session management and it seems that
Simple rails app using Postgres DB, getting 'integer out of range' error when trying
My Rails app is starting to need complicated queries. Should I just start using
My Rails app mockup is up on Heorku and is using images hosted on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.