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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:15:40+00:00 2026-05-14T23:15:40+00:00

I have a basic has_many through relationship: class Foo < ActiveRecord::Base has_many :bars, :dependent

  • 0

I have a basic has_many through relationship:

class Foo < ActiveRecord::Base
  has_many :bars, :dependent => :destroy
  has_many :wtfs :through => :bars

  accepts_nested_attributes_for :bars, :wtfs
end

On my crud forms I have a builder block for the wtf, but I need the label to come from the bar (an attribute called label for instance). What’s the proper method to do this?

Here’s the most simple scaffold:

<h1>New foo</h1>

<% form_for(@foo) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>

  <h2>Bars</h2>
  <% f.fields_for :wtfs do |builder| %>
    <%= builder.hidden_field :bar_id %>
    <p>
     <%= builder.text_field :wtf_data_i_need_to_set %>
    </p>
  <% end %>

  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

<%= link_to 'Back', foos_path %>
  • 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-05-14T23:15:41+00:00Added an answer on May 14, 2026 at 11:15 pm

    The answer was found in analyzing how the rails FormBuilder works. So in the example above where I need to access the actual wtf object so I can get a property on bar, I need to do the following:

     <h2>Bars</h2>
      <% f.fields_for :wtfs do |builder| %>
        <%= builder.hidden_field :bar_id %>
        <p>
         <%= builder.label builder.object.bar.data_i_need_for_a_label %>
         <%= builder.text_field :wtf_data_i_need_to_set %>
        </p>
      <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My understanding is that the big change (performance wise) that… May 16, 2026 at 11:05 am
  • Editorial Team
    Editorial Team added an answer A couple of things to try: Your URL doesn't need… May 16, 2026 at 11:05 am
  • Editorial Team
    Editorial Team added an answer Your original rules seems to work OK for it's job,… May 16, 2026 at 11:05 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a basic has_many :through relationship that is bi-directional: calendars have many calendar_calendar_events
I have 3 models sites, user_favorites and users. Relevant relationships: class Site < ActiveRecord::Base
I have a basic solution file (.sln) where I was able to reproduce a
I have a task tracking application, which is very basic. It currently has a
I have 2 tables: Movies: movieID Users: userID These tables have a many to
I haven't implemented a search feature before and feel a bit stuck. I have
I need a Class which has an semi-automatic 'to_s' method (to generate XML in
I have 3 relevant tables. User, Orders, and Viewables The idea is that each
I have a ListView with different layouts for different items. Some items are separators.
I seem to have a problem, I have a growing business to run but

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.