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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:39:39+00:00 2026-06-06T21:39:39+00:00

Here are my models: **Resource** has_many :users, :through => :kits has_many :kits **User** has_many

  • 0

Here are my models:

**Resource**
has_many :users, :through => :kits
has_many :kits

**User**
has_many :resources, :through => :kits
has_many :kits

**Kits**
belongs_to :resource
belongs_to :user

Users in the application can add resources to their kits by clicking on them. Then I can find out which resource a User has by doing:

@user.resources

Now a user can also submit a resource for approval. I want to track which user submitted which resource. How can I do this so that I can do the following:

Resource Controller

def create
current_user.resources.create(params[:resource])
end

I would like to be able to do something like:

@user.submitted_resources.count
  • 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-06T21:39:41+00:00Added an answer on June 6, 2026 at 9:39 pm

    Given models with the following associations (and the necessary tables, columns, etc.):

    **Resource**
    has_many :users, :through => :kits
    has_many :kits
    belongs_to :submitter, class_name: "User"
    
    **User**
    has_many :resources, :through => :kits
    has_many :kits
    has_many :submitted_resources, class_name: "Resource", foreign_key: "submitter_id"
    
    **Kits**
    belongs_to :resource
    belongs_to :user
    

    Note the added has_many :submitted_resources, class_name: "Resource", foreign_key: "submitter_id" on the User model. This assumes that there is a column on the Resources table named submitter_id (which you said you had added). After adding this association, you can reference all the resources a User has submitted with the User#submitted_resources method (i.e. @user.submitted_resources.count).

    I also added the belongs_to :submitter, class_name: "User" association to your Resource model, which allows for easy referencing the User that created the record, but it isn’t necessary to accomplish what you asked.

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

Sidebar

Related Questions

Here are the relevant models: User Product Order A User can sell or buy
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
here is my model class gameUserTrophyInfo(models.Model): user = models.ForeignKey(userInfo) trophy = models.ForeignKey(gameTrophyInfo) date =
I have gone through tons of the form_for nested resource questions and can't get
I have a model User, that has_many belongings (a belonging belongs_to a user). I
so i have a little tricky combination here Company has many Users User belongs
I'm a little baffled here and can't seem to find the proper resource or
Okay, so here's an example scenario. There is a student resource resources :students ,
This question is a continuation of my previous question here zend models architecture (big
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here

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.