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

  • Home
  • SEARCH
  • 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 8611657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:25:48+00:00 2026-06-12T04:25:48+00:00

Ok, I have a huge trouble finding the words to explain my problem. I

  • 0

Ok, I have a huge trouble finding the words to explain my problem. I hope you can understand and help me because frankly, I am going insane.

Let’s say I have four models: User, Team, Report and UserReport. I have this:

class Report < ActiveRecord::Base
  belongs_to :team
  has_many :user_reports
  accepts_nested_attributes_for :user_reports
end
class UserReport < ActiveRecort::Base
  belongs_to :report
end

class ReportsController < ApplicationController
  def new
    @team = Team.find params[:team_id]
    @report = Report.new
    @team.users.each do |user|
      ur = @report.user_reports.build
      ur.user_id = user.id
    end
  end
end

What I have now is that the user of the site chooses the Team. In the team are, of course, a bunch of Users. For each of them, a UserReport is to be added to the Report. In the new.html.haml, I would write this:

=fields_for :user_reports do |b|
  =b.hidden_field :user_id, user.id
  =user.name

And there is the problem. How can I get the user.name or the user.id or anything in this form builder? I need to output the user name there, because otherwise the site user wouldn’t be able to know which is who.

I do hope you understood my problem, I’m kind of desperate by now.

  • 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-12T04:25:50+00:00Added an answer on June 12, 2026 at 4:25 am
    class ReportsController < ApplicationController
      def new
        @team = Team.find params[:team_id]
        @report = Report.new
        @urs = []
        @team.users.each do |user|
          ur = @report.user_reports.build
          ur.user_id = user.id
          @urs << ur
        end
      end
    end
    

    In your view:

    = form_for @report do |f|
      =f.fields_for :user_reports, @urs do |b|
        =b.hidden_field :user_id
        =b.object.user.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day... I have huge trouble with this and it drives me insane. My
I've recently upgraded my Xcode version and have been having huge trouble trying to
I am having some trouble where I have a huge paint function in java
I have a rather unique problem that I'm having trouble solving. I have a
I have huge dictionaries that I manipulate. More than 10 Million words are hashed.
I am in big trouble at the moment. We have a huge JS library
I have huge amount of data from database, i need to get or store
I have huge data which is static. I need to save it within the
I have huge amount of txt files which contains 64x64 matrices consisting of integers.
I have huge amont of geographic data represented in simple object structure consisting only

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.