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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:26:32+00:00 2026-05-21T02:26:32+00:00

In my application, a user is allowed to assign another user as their account

  • 0

In my application, a user is allowed to assign another user as their “account manager” and the account manager would be allowed to modify all user info. I defined the following ability:

can :manage, User do |user|
    user == current_user or user.account_manager == current_user
end

A user also has some nested resources (e.g: publications). I defined the following ability:

can :manage, Publication do |publication, user|
    publication.user == current_user or user == current_user or user.account_manager == current_user
end

In the views I check using the following:
can? :update, @publication, @user_we_are_accessing
can? :create, Publication.new, @user_we_are_accessing.

Everything works just fine so far. My problem is with the controller. In my PublicationsController I added:
load_and_authorize_resource :user
load_and_authorize_resource :publication, :through => :user

However this always throws AccessDenied, because the check for publication is not passing the user object to the ability (trying to inspect the user object in the ability shows nil).

Any ideas how I can go about implementing this?

tl;dr: Using CanCan to authorize access to resources. User can assign another user as account manager. User has nested resources. Problem: nested resource is not accessible by account manager.

  • 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-21T02:26:32+00:00Added an answer on May 21, 2026 at 2:26 am

    I solved this by doing the following:

    1) replaced load_and_authorize_resource :publication with just loading the resource load_resource :publication
    2) Added a before_filter :authorize after the load_resource call with the following implementaiton:

    def authorize
        raise CanCan::AccessDenied unless can? :manage, @publication, @user
    end
    

    This works, but I was hoping for a way that would solve this in the devise way, if there is such a thing. Thoughts and feedback are appreciated.

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

Sidebar

Related Questions

We have a customer that would like to modify application user messages that we
I have an application I am developing where the user is allowed to email
In an ASP.NET WebForms application I would like to allow the end-user to browse
I am working on an application where all user authentication happens in a ColdFusion
i want to make such an application that user is not allowed to uninstall
I have created a web part in asp.net application and allowed user to change
I am working on an application in which a user is allowed to fill
In my current application I have allowed the user to submit an image to
In my application user can add there reminder for the specific day and reminder
Can you use FluentHTML or other alternatives in an web application user control? Can

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.