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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:21:16+00:00 2026-06-06T07:21:16+00:00

I am trying to grab a user job notes but am not sure what

  • 0

I am trying to grab a user job notes but am not sure what I am doing wrong. At first I was able to get the job and note working properly when I nested just the two but when I wanted to get the user job notes then my code broke.

notes.controller new

def new
  @note = @user_note.notes.new
end

private 

def user_note
    @user = current_user
    @job = @user.job.find(params[:job_id])
end

user.rb

has_many :jobs
has_many :notes, through: :jobs

job.rb

belongs_to :user
belongs_to :note

notes.rb

has_many :jobs
has_many :users, through: :jobs

In rails console if I were to type the following code it works fine.

User.last.jobs

If I were to try to code below it does not

User.last.jobs.notes

then I get the error

undefined method `notes' for #<Job:0x007fe37dc77190>

How can I properly grab the user_id when creating a note for a job? right now it grabs the job id for the note but does not grab the user id. I would like to be able to find notes from a job and user. Any ideas what I am doing wrong and how I can fix this?

  • 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-06T07:21:19+00:00Added an answer on June 6, 2026 at 7:21 am

    The basic fault is that you are asking through 2 has_many relations. This is not possible. You could do something like:

    user = User.last
    user.jobs  # returns all the user's jobs
    user.notes # returns all the user's notes
    user.jobs.each_with_object({}) {|job, hash| hash[:job.id] = job.note_ids]} 
      # returns a hash with user's job_id as keys and an array of related note_ids as value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What am I doing wrong? - I'm trying to grab the user's locale from
I'm trying to make my application grab a photo from the user's Photo library
I am trying to grab all the td elements between the first two that
I was trying to grab the ID of the SPAN tag when a user
I'm trying to use Facebook's Graph API to grab a user's insights data, and
I'm trying to grab data from a JSON on an external site but the
I am trying to identify a user ID number, to grab a Student row
Hey so I am trying to grab the user input text within a textarea
So I'm trying to get a popup box to show when a user rates
I am trying to grab the string/object from the treeview. So when a user

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.