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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:57:55+00:00 2026-06-14T02:57:55+00:00

Using CanCan for authorization and Devise for authentication. I have three roles. Admin role

  • 0

Using CanCan for authorization and Devise for authentication. I have three roles. Admin role has access to all actions. But when I am logged in as an admin, I still get Access Denied. What am I doing wrong?? Also I have been following this wiki for implementation

This is my controller code

class LocationController < ApplicationController
  #before_filter :authenticate, :only => [:title_clearing]
  before_filter :authenticate_user!
  load_and_authorize_resource

  def show
    @data = []
    if params[:Date].match(/^(19|20)\d\d[- \/.](0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])$/).nil? == true
      @message = "Wrong Date Format"
    else
      @data = Location.show(params[:Date])
      if @data.size == 0
        @message = "No data exists for "+ params[:Date]
      else
        @message = "Data loaded successfully for "+ params[:Date]
      end
    end

    if params[:Date] == "all"
      @message = "All records loaded"
      @data = Location.show("all")
    end

  end
end

In the ability.rb

if user.is? :admin
    can :all, :location 
end
if user.is? :titleclearing
    can :title_clearing, :location
end
if user.is? :acquisitions
    cannot :title_clearing, :location 
end

In the user model

def role?(role)
    roles.include? role.to_s
end
  • 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-14T02:57:56+00:00Added an answer on June 14, 2026 at 2:57 am

    User proper CanCan convention:

    if user.is? :admin
      can :manage, Location
    end
    

    Or, you can manage all:

    can :manage, :all
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using devise for authentication and cancan for authorization in my application.
I'm trying to get some basic authentication/authorization with devise/cancan with Rails. Rather than using
I'm using cancan as my authorization engine. I already have the roles in user:
While trying to add roles-based authentication (using CanCan and Devise) to my project I
With a standard install of Rails_Admin using Devise for authentication and CanCan for authorization,
I'm using Devise and CanCan to setup authentication and authorization in my app. Now
I am using cancan for authorization. I have a shared view which need authorize
I have a rails application with 2 roles, say admin and user. But the
I'm using devise and cancan in a Rails 3.2 project. I have an event
I'm using Cancan, Devise, Rails 3 for my ordering application. Each user has many

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.