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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:07:56+00:00 2026-06-18T17:07:56+00:00

In the project management app I’m working on, I’m currently working on a page

  • 0

In the project management app I’m working on, I’m currently working on a page for managing tickets, which I want should contain of the following:

- The tickets that the user has created
- The tickets that belongs to projects that the user has created

The tricky part is to use the right code in the controller, which is where I need help.
‘@users_tickets’works fine, as well as ‘@owned_projects’. However, the last thing which is creating an array that contains of the tickets that belongs projects that the user owns, is something I need help me (yes, I understand that my poor try with an each loop is totally the wrong way to go here).

How can I achieve what I want?

Tickets controller:

1.    def manage
2.      @users_tickets = Ticket.where(:user_id => current_user.id)
3.      @owned_projects = Project.where(:user_id => current_user)
4.
5.      @owned_projects.each do |project|
6.          @tickets_for_owned_projects = Ticket.where(:project_id => project.id)
7.      end
8.    end

Tables:

tickets table:

project_id
ticket_status_id
user_id
title
description
start_date
end_date

projects table:

user_id
title
description
start_date
end_date
  • 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-18T17:07:57+00:00Added an answer on June 18, 2026 at 5:07 pm

    If you’re using a has_many association, then it should as simple as

    class User < ActiveRecord::Base
      has_many :projects
      has_many :tickets
      has_many :project_tickets, through: :projects, class_name: 'Ticket', source: :tickets
      #...
    end
    
    class Project < ActiveRecord::Base
      has_many :tickets
      #...
    end
    
    # in tickets controller
    def manage
      @tickets = current_user.tickets
      @tickets_for_owned_projects = current_user.project_tickets
    end
    

    UPD: The approach above should work. I’m literally falling asleep right now and can’t define what is wrong here. Would really appreciate if someone looked into it.

    Here’s another way around though.

    class User < ActiveRecord::Base
      has_many :projects
      has_many :tickets  
    
      def project_tickets
        result = []  
        self.projects.each do |project|
          result << project.tickets
        end
        result.flatten
      end
      #...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project management app, where every company (which uses our app)
I'm currently learning rails by creating a simple project management app. I've gotten to
i am working on a online file management project.In which we are storing references
I am building a project management app and I am not sure which is
I created a Test project that I want to delete, using the following command:
I'm working on a project management app, and in the app, I have project_managers
I'm working on a sort of project management app with Rails (my Rails skills
I'm in rails 3.0 and I'm working on a project management app. I'd like
I'm working on a web app for a class. It's basically a project management
Consider a project management app that uses git at backend. The new versions are

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.