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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:40:56+00:00 2026-05-20T08:40:56+00:00

In my system there are many types of users (4), based on the user

  • 0

In my system there are many types of users (4), based on the user that is logged in they have access to only certain information.

For example I am trying to do something like this in my Client model:

 class Client
     def self.allowed
        if current_user.is_a?(SuperAdmin)
          return self.all
        elsif current_user.is_a?(Client)
          return [current_user]
        elsif current_user.is_a?(ClientAdmin)
          return [current_user.client]
        end
      end
   end

The problem is, it seems my model doesn’t have access to the current_user helper method. (undefined local variable or method `current_user’ for #)

I have 2 questions:

  1. How can I fix this
  2. Should logic such as getting back the allowed client be done in the model?
  • 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-20T08:40:57+00:00Added an answer on May 20, 2026 at 8:40 am

    Using your methodology, I would define the method to allow passing in a user to check, as follows:

    class Client
       def self.allowed(user)
          if user.is_a?(SuperAdmin)
            return self.all
          elsif user.is_a?(Client)
            return [user]
          elsif user.is_a?(ClientAdmin)
            return [user.client]
          end
        end
     end
    

    Then, your controllers can decide which user should be checked based on the action being performed (although this will usually be current_user, this will free up your implementation to work with any user, so if you decide to add functionaly that depends on that fact later you’re covered).

    That being said, you should take at an authorization library; I personally really like CanCan. It allows you to define authorizations in one place, using a style similar to the one you present here. The author, Ryan Bates, has a great screencast on using CanCan.

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

Sidebar

Related Questions

In the system there is a singleton for currently logged user (our own user
I have a system where I need to login three user types: customers, companies,
I have a website that asks numerous users to fill out a form. There
I am working with a 2010 TFS system where there are many projects and
There are many systems that depend on the uniqueness of some particular value. Anything
I am the root user of the system there is a file: D:\XAMPP\htdocs\magento_41\magento\ which
Swing newbie question... I have a system where there is a large number of
I have some code that allows users to upload file attachments into a varbinary(max)
I have lots of forms in my MVC3 application that require the user to
First off, I'm aware that there are many questions related to this, but none

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.