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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:17:25+00:00 2026-05-31T14:17:25+00:00

I have a simple Ability.rb set up listed below: if user.role? :super_admin can :manage,

  • 0

I have a simple Ability.rb set up listed below:

if user.role? :super_admin
  can :manage, :all
elsif user.role? :registered
  can :review, [Card, Deck], :visible => true
end

Where the alias :review => :index, :list, :show, :to. Both Card and Deck tables have the visible column with the boolean option. Currently every object in the tables have :visible => false. Therefore, I’m expecting that a user with the registered role will not be able to :review any of the objects, but this is not the case. Restrictions at the controller level works fine (edit and delete are not accessible), but I can’t seem to restrict the viewing of resources using the hash of conditions. Any thoughts?

Edit: I have authorize_resource in the two controllers. Using Ruby 1.9.2, Rails 3.1, and CanCan 1.6.7. I’m using devise 1.4.9 for authentication. MySQL is the database.

Edit:
Well.. I figured out a way to restrict resources based on the conditions. Even though I had authorize_resource in all my controllers (and it worked for restricting access to the methods), I had to add authorize! to the methods that I wanted to restrict the resources to. For example, to restrict the show action for Decks with the condition of :visible => true, I had to add authorize! as such:

def show
  @deck = Deck.find(params[:deck_id]
  authorize! :review, @deck
end

To be honest, I am not satisfied with this solution, since I don’t see a reason why authorize_resource wouldn’t work. I would love to see an explanation.

  • 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-31T14:17:26+00:00Added an answer on May 31, 2026 at 2:17 pm

    Are you calling

    load_resource_authorize_resource 
    

    in your controller just like that, or are you including a model to authorize?

    I discovered that I can replicated your issue if I type something like:

    load_resource_authorize_resource Deck
    

    I think the reason the latter doesn’t work because you are asking CanCan to authorize “Deck” arbitrarily, as opposed to authorizing a controller action, which is what you really want to do.

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

Sidebar

Related Questions

Hey all. I have the following code: http://jsfiddle.net/g7Cgg/ As you can see, there are
I have a set of classes and interfaces which have a relatively simple hierarchy,
In Moss 2007 you have the ability to set the target audience for each
I have a sample dataform and I would like to remove the ability to
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple class with width and height member fields which define number of
I have simple php validation form that is halfway working. If you leave the
I have simple JavaScript snippet: var obrazek = [{nazwa: "Sniadanie", wiek: 100, autor: "Alicja"},{nazwa:
I have simple script with EventMachine, Fibers and faye require faye require em-synchrony require
I have simple database - one table with 6 collumns. 3 of them i

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.