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

  • Home
  • SEARCH
  • 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 7498769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:35:31+00:00 2026-05-29T19:35:31+00:00

Can CanCan be used to limit which parameterized views a user can access? We

  • 0

Can CanCan be used to limit which parameterized views a user can access?

We produce images that users buy individual access to.

For instance:

Bob has access to images 1, 3, and 4.
Joe has access to images 2 and 4.
Steve has access to image 5.

The url would be something like site.com/images/1.

Is there a way I can restrict which number (parameter) of a view a user can view? With or without CanCan?

I’m using Rails 3.2.1

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-29T19:35:32+00:00Added an answer on May 29, 2026 at 7:35 pm

    Here’s an example from one of my projects.

    classes

    class App
      has_many :app_ownerships
    end
    
    class User
      has_many :app_ownerships
    end
    
    class AppOwnership
      belongs_to :user
      belongs_to :app
    
    
    end
    

    somewhere in ability.rb

    can :read, App do |app|
      # find all ownerships with at least read-only access (access_level == 1)
      active = app.app_ownerships.select do |o|
        o.app_id == app.id && o.user_id == user.id && o.access_level >= 1
      end
      active.length > 0
    end
    

    somewhere in app_controller.rb

    def show
      @app = App.find params[:id]
      authorize! :show, @app # throws exception if not authorized
    
      ...
    end
    

    Hope you can use this snippet for your needs.

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

Sidebar

Related Questions

Am trying to hide this publish 'tick-box' from non-admin users. I used the CanCan
Can somebody point me to a resource that explains how to go about having
Can a LINQ enabled app run on a machine that only has the .NET
I was wondering how I can define an ability class and serve that ability
I have tried every way possible and can't seem to limit the scope_to method
I am using cancan and trying to get it to limit equipment shown for
I have several controllers that require a correct user for their edit/update/delete actions. What
I was looking for a tool which can can auto-generate the DML stored procedures
Is it possible to define cancan for anonymous users in devise? Where an anonymous
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.