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

The Archive Base Latest Questions

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

I have 3 models: Users, Customers, Issues. Below is the code for these models

  • 0

I have 3 models: Users, Customers, Issues. Below is the code for these models

Customer model:

class Customer < ActiveRecord::Base
  belongs_to :se
  belongs_to :user
  has_many :issues
end

Issues model:

class Issue < ActiveRecord::Base
  belongs_to :customer
end

Users model:

class User < ActiveRecord::Base
  has_many :ses
  has_many :customers
  has_many :issues, :through => :customers

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name,     :last_name, :cell_ph, :area


end

I would like to display only the issues that belong to a particular user. I am having problems making this work. Can someone suggest how I might create an index method that would accomplish this?

Here is my index method where I’m trying to use devise’s current_user method to identify the user who’s logged in to the view:

  def index
    @issues = Issue.where(:user == :current_user)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @issues }
    end
  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-29T05:25:50+00:00Added an answer on May 29, 2026 at 5:25 am

    You can’t do what you’re doing because an Issue doesn’t have a user.

    According to Rails guides (second example on http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association session), you can nest the has_many using a has_many :through.

    So you should be able to do this:

    current_user.issues

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

Sidebar

Related Questions

I have 3 models sites, user_favorites and users. Relevant relationships: class Site < ActiveRecord::Base
I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>
I have 3 models: class DropShipOrderLineItem < ActiveRecord::Base belongs_to :drop_ship_order belongs_to :line_item validates_associated :drop_ship_order
I have these 3 models in models.py class Customer(models.Model): name = models.CharField(max_length=50) .... class
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to
I have 3 models class User < ... belongs_to :language has_many :posts end class
Suppose I have the following models: class User(models.Model): pass class A(models.Model): user = models.ForeignKey(User)
I have a nested form with the following models: class Incident < ActiveRecord::Base has_many
I have a Job model that belongs_to three users (customer, employee, and qa). The
I am using STI for my user models. I have an User class, and

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.