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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:15:16+00:00 2026-06-04T19:15:16+00:00

I am playing around with Mongoid (NoMySQL Database), DEVISE and CANACN I have read

  • 0

I am playing around with Mongoid (NoMySQL Database), DEVISE and CANACN

I have read the manual (https://github.com/ryanb/cancan/wiki/Role-Based-Authorization),
but I dont wanna use the “roleMask”-calculation. I wanna use an Array (or Hash) -field instead, containing the roles of a user.

class User
  include Mongoid::Document
  field :email, :type => String, :null => false
  field :roles, :type => Array, default: -> { ['User'] if new_record?}

Is this possible in any way? And when yes, how? 🙂

many thanks in advance

  • 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-04T19:15:18+00:00Added an answer on June 4, 2026 at 7:15 pm

    Cancan doesn’t really care how your roles work – your ability file is pure ruby so the logic is entirely up to you. For example you might have this in your ability:

    can :manage, Product
    

    If you want to restrict this to users whose roles array contains a certain value then you could do

    if user.roles.include?('Admin')
      can :manage, Product
    end
    

    Since your ability is just a ruby class you can do pretty much anything that you can express in ruby.

    There are multiple ways of dealing with inheritance, two are outlined in the cancan wiki.

    One way involves changing how you check for a role: if you had an admin? method, then instead of just checking for the presence of the admin role it would also check for the presence of any other roles that should inherit all of that access.

    Another way is to split your ability file into methods named after the role, for example all the statements for the editor role would be in the editor method, the manager method contains all the statements for the manager role etc. If for example managers need to inherit the access an editor has then call the editor method from manager.

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

Sidebar

Related Questions

After playing around with https://battlelog.battlefield.com/ and https://github.com/ I noticed it does not reload the
I have been playing around with various methods of making the Visitor pattern in
I've been playing around with Simple.Data and have run across something that I can't
I'm just playing around with some code but it seemed to have the specific
Playing around with Google Maps these days, with some directions. I have a map
Just playing around with interfaces and I have a question about something which I
I am playing around with the AVAudioRecorder so I can have it in my
Playing around in order to learn XSLT, I have the following XML file and
Started playing around with jQuery and the jsTree plugin yesterday, and have it successfully
We are playing around with Atlassian products and I have prepared an agile sprint

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.