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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:50:29+00:00 2026-05-27T14:50:29+00:00

I have two types of users: managers, and employees. I use one User controller

  • 0

I have two types of users: managers, and employees. I use one User controller for both of them.

What I did was add :manager_id to the user table, and put the following in the user model:

class User < ActiveRecord::Base
has_many :employees, :class_name => 'User', :foreign_key => :manager_id
belongs_to :manager, :class_name => 'User'

Sounds simple enough.

But now I want to define the user type. If an user has a manager, he is an employee. If a user has no manager, he is a manager.

What do I need to add to the model so I reference the user type in my views like such:

<% if current_user.manager? %>
You are a manager.
<% else %>
You are not a manager.
<% end %>

I tried to define the user type in the user.rb model but I’m getting an “undefined method ‘manager?’ for nil:NilClass” error :

def manager?
    manager_id.nil?
end

def employee?
    !manager?
end
  • 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-27T14:50:30+00:00Added an answer on May 27, 2026 at 2:50 pm

    Like Ryan Bigg said, you need to check out the error message a little closer. It isn’t that manager? doesn’t exist as a method on an instance of User, it’s that it doesn’t exist on Nil. When there isn’t a current_user, current_user returns nil, which you then call manager? on.

    Try this to avoid this error:

    <% if current_user && current_user.manager? %>
      Manager!
    <% elsif current_user %>
      Not a manager, but a user!
    <% else %>
      Not even a user.
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two types of users on my site: Normal user Supplier How do
I'm using Django 1.2 and I want to have two user types (one for
I have two types of users: user and editor. I have a User model
I have two types of users for my system, normal human users with a
I've a system, that have two types of users (Companies and individuals).all types have
i have two tables in my database : Users : contain user information UserTypes
So, I have two types of users who may login or register: merchants or
I have two types of roles [Admin, HelpDeskAdmin]. I have a single logon view(both
I have two types of users Client and Vendor for my MVC 3 application.
I have a users table where there are two types of users in it,

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.