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

The Archive Base Latest Questions

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

I am using cancan for permissions and I would like it so users cannot

  • 0

I am using cancan for permissions and I would like it so users cannot see other users when visiting their profile/users page. User should only be able to see themselves.

In my ability.rb file I have

class Ability
include CanCan::Ability

def initialize(user)
   user ||= User.new # guest user (not logged in)

   if user.role? :admin
     can :manage, :all
   elsif user.role? :rookie 
     can [:update, :destroy], [Album, Photo, User]
     can :read, :all
   end

  can :manage, Album, :profile => { :user_id => user.id }
  can :manage, Photo, :profile => { :user_id => user.id }
  can :manage, Video, :profile => { :user_id => user.id }
  can :manage, Comment, :blog => { :profile => { :user_id => user.id } }
  can :manage, User, :id => user.id
 end
end

In my users_controller I have

class UsersController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource 

 def index
   @user = current_user
 end

 def show
  @user = User.find(params[:id])
 end
end

The above usually works but since user is the primary model I am not sure how I can resolve this. Rails gives me the error

undefined method `user_id'
  • 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-31T01:17:30+00:00Added an answer on May 31, 2026 at 1:17 am

    It should be:

    #ability.rb:
    can :manage, User, :id => user.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities. User and Role. I am using Devise and CanCan. They
I am using Ruby's net-ssh library to remotely execute shell commands. I would like
I'm using Cancan, Devise, Rails 3 for my ordering application. Each user has many
I'm quite new to this and I'm using cancan + devise for my user
I'm using Cancan to control User abilities, and have recently run into an odd
I'm using cancan as my authorization engine. I already have the roles in user:
Using RSpec and Cancan, I have this test which fails with: Failure/Error: User.should_receive(:new).and_return(@user) expected:
Hello I'm actually using Ryan' Bates cancan gem authorization to make my application's users
I am using cancan with one role per user. The roles are integers instead
I am using devise for my authentication system and cancan for permissions. I am

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.