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 6175183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:52:49+00:00 2026-05-23T23:52:49+00:00

Using devise , I have a User model. I do not have a user

  • 0

Using devise, I have a User model. I do not have a user controller.

To use CanCan I need to do (below) at the top of my controllers

# Authorization w Devise & CanCan
before_filter :authenticate_user! # Devise, signed in users only
load_and_authorize_resource # CanCan

Where do I add this so I can have permissions for the User model given I have no user controller?

Thanks

  • 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-05-23T23:52:50+00:00Added an answer on May 23, 2026 at 11:52 pm

    You can add that code to any controller for which you need authentication, you don’t need an UsersController

    before_filter :authenticate_user!
    

    this line require a valid user signed in with devise, so if you try to access a controller with this before_filter without being logged you’ll be redirected by devise to the sign_in_path

    load_and_authorize_resource # CanCan
    

    this other line will fill an instance variable to a default value (if not already set) and then check your privileges using the Ability class, so assuming you have an ArticleController it will do the following behind the scenes (actual code is based on the current action)

    # for the show action
    @article = Article.find(params[:id])
    raise CanCan::AccessDenied unless can(:read, @article)
    

    The can(:read, @article) statement is the hearth of CanCan library, it will return a boolean value based on your ability class. Can read more on it here

    If your whole application requires authentication you can simply add the before_filter :authenticate_user! line to the ApplicationController

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

Sidebar

Related Questions

I am using Devise in Rails 3, and have a User model in rails
I have a User model that Devise manages - i.e. all users have email
I am using Devise and I have it so a User clicks log in
I'm building an app in Rails 3. I currently have a user model which
I'm using Devise as authenticating solution in Rails and I have a cached fragment
I'm using Rails 3 with devise. I have a table books which has a
I have a User model, a Workout model and a Exercise model. I am
I have used RESTful techniques to generate a model (in fact, I am using
I'm developing a Rails 3 app using Devise and CanCan. The app allows anonymous
I have an app that's a simple clone of reddit. Using Devise you can

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.