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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:17:41+00:00 2026-06-01T07:17:41+00:00

I have a resource database where resources can belong to different locations. Users and

  • 0

I have a resource database where resources can belong to different locations. Users and groups (self-referential user table) can have different roles on different locations. Groups can be inside other groups. Authorization works well for single users using ‘if_attribute’ to check if the location_id is among the location_ids that the user is allowed to show, edit, etc.:

has_permission_on :locations do
  to [:show, :new, :create, :edit, :update, :destroy] 
  if_attribute :id => is_in { (user.permissions.where(:role => "admin").collect {|i| Location.find_by_id(i.location_id).subtree_ids}.flatten.uniq )}
end

Since the groups can be “nested” inside each other, I have figured that I’ll have to use a recursive method to find all the “legal” location ids. I tried this:

 has_permission_on :locations do
  to [:show, :new, :create, :edit, :update, :destroy] 
  if_attribute :id => is_in { (user.permissions.where(:role => "admin").collect {|i| Location.find_by_id(i.location_id).subtree_ids} + find_group_location_ids(user)).flatten.uniq }
end

with the method defined outside the ‘authorization do’-routine:

def find_group_location_ids(user)
  location_ids = []
  nested_group_location_ids(user)
  def nested_group_location_ids(user)
    user.group_memberships.each do |gm|
      location_ids = location_ids + gm.user.location.id
      nested_group_location_ids(gm.user)
    end
  end
  return location_ids
end

The problem is that the method call doesn’t find the method. I get this error:

NoMethodError (undefined method `find_group_location_ids’ for (Authorization::Engine::AttributeValidator:0x7fb63448e2b0)

I have tried to place the method definition on a lot of different places, but with no luck.

How can I use if_attribute to see if an id is inside an array from a recursive method?

  • 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-01T07:17:42+00:00Added an answer on June 1, 2026 at 7:17 am

    I got som help from steffenb at the declarative_authorization group at google groups (he is the author of declarative_authorization). The solution was to move the method to the user model:

    def find_group_location_ids
      location_ids = []
      nested_group_location_ids(self)
      def nested_group_location_ids(user)
        user.group_memberships.each do |gm|
          location_ids = location_ids + gm.user.location.id
          nested_group_location_ids(gm.user)
        end
      end
      return location_ids
    end
    

    and to call it in this way from autorization_rules.rb:

    has_permission_on :locations do
      to [:show, :new, :create, :edit, :update, :destroy] 
      if_attribute :id => is_in { (user.memberships.where(:role_id => "admin").collect {|i| Location.find_by_id(i.location_id).subtree_ids}  + user.find_group_location_ids).flatten.uniq }
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an Applications table and a Resources tables. Since many resources can work
Say that you have an application where different kind of users can sign: Firms,
Database resources, that can be accessed from webpage that I'm currently working on, have
I have a couple of jobs that use a shared resource (database), which sometimes
I have a simple Ability.rb set up listed below: if user.role? :super_admin can :manage,
I have a database of resources with the typical address, email and all that
I have a database design where i store image filenames in a table called
so i have a little tricky combination here Company has many Users User belongs
I have a resource file named filetypes.resx. Some how I figured out to bind
I have couple resource DLLs that I currently load when application starts using following

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.