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.
In your view: