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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:25:10+00:00 2026-06-05T08:25:10+00:00

I’m trying to set up an authorization/authentication system, and I’m getting confused, so I

  • 0

I’m trying to set up an authorization/authentication system, and I’m getting confused, so I have a couple of questions:

  1. In a lot of tutorials, people set up a user/role HABTM relationship.
    I get that this allows for each user to have multiple roles, but if
    you want each user to only have one role, is this necessary? If I want to have options for “active” and “inactive” users, should those
    be roles or something else?
  2. In the Cancan wiki, it says if you want one user to have one role, you should just make it an attribute and then use “can
    :manage, :all if user.role == “admin””, but isn’t that
    dangerous because each time “admin” is just a string? Does this
    matter? What’s a better way to deal with this?

I’ve tried my best to read through the documentation for everything involved and I started with this tutorial

http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html

although I’ve also read
http://starqle.com/articles/rails-3-authentication-and-authorization-with-devise-and-cancan-part-1/ and
tonyamoyal.com/2010/09/29/rails-authentication-with-devise-and-cancan-part-2-restful-resources-for-administrators/

I just can’t really get it to work the way that I want to. How do I do this?

  • 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-05T08:25:12+00:00Added an answer on June 5, 2026 at 8:25 am

    1. You do not need to multiple roles or a role table

    CanCan is agnostic to how you define roles in your application. You could just as easily have a role field in your user model.

    As for “active” and “inactive” users, you have two options. You could have a field for that status, or you could have an “inactive” role and consider any other role “active”. This depends on what you mean by “active” and how you are using that information in your application.

    2. There is nothing wrong with storing a user’s role in a string.

    The fact that the role is stored as a string doesn’t make it less safe. You should, however, use attr_protected to prevent mass assignment of the user role.

    attr_protected :role
    

    That way, users won’t be able to update their own roles.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.