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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:15:23+00:00 2026-06-02T19:15:23+00:00

I have a users table. It contains a field user_type. I added the following

  • 0

I have a users table. It contains a field “user_type”.
I added the following scope stmts to the user.rb file:

scope :uemployee, where(:user_type => 'employee')
scope :uclient, where(:user_type => 'client')
scope :ucontractor, where(:user_type => 'contractor')

I created a view and I would like it to list he employees.
Here is the code I’m trying to use:

 <% @users.uemployee.each do |user| %>

But, I get “undefined method `uemployee’ for nil:NilClass”

What am I doing wrong?

Thanks

  • 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-02T19:15:25+00:00Added an answer on June 2, 2026 at 7:15 pm

    Looks like you wanted to do this:

    <% User.uemployee.each do |user| %>
    

    But this is considered to be a bad practice. You have to prepare you data in a controller and a view just cycles through it:

    # in a controller's action
    @users = User.uemployee
    
    #in a view
    <% @users.uemployee.each do |user| %>
    

    But even this isn’t the best approach. If you create the file views/users/_user.html.erb which shows the info about a particular user (current user will be available as a simple user variable, without the @) then you can simply write:

    # in a view
    <%= render @users %>
    # remember, @users variable was set in your controller
    

    then Rails will cycle through all the users “inside” the @users variable and show them one-by-one.

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

Sidebar

Related Questions

I have a table that contains articles posted by users. The structure of the
Say I have a table called Users, which contains your typical information: Id, Name,
I currently have a user's table which contains a one-to-one relationship for Youtube OAuth
I have a table (user) that contains user information. I have another table (userview)
I have a table which contains User IDs, Period IDs and Qty: User Period
I have a database table which contains an unsigned integer field to store the
I have two relational tables: the Profiles table which contains 3 kinds of user
I have a single product table with multiple fields which contain user evaluations of
I have a table that contains intervals: CREATE TABLE tbl ( user_id: INTEGER, start:
I have a table that contains id, created, user_id. I'm wondering if there is

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.