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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:00:47+00:00 2026-05-23T09:00:47+00:00

I have a model named Order and another model named Member and when I

  • 0

I have a model named Order and another model named Member and when I try to display fields from the Members model in my Orders view it doesn’t even show when using the fields_for tag. Heres what my code looks like.

order model

class Order < ActiveRecord::Base
  has_many :members 
end

member model

class Member < ActiveRecord::Base
  belongs_to :order
end

orders controller

class OrdersController < ApplicationController

  def new
    @order = Order.new
    3.times { @order.members.build }
    @title = "Order Form"
  end

  def create
    @order = Order.new params[:order]
    if @order.save 
      flash[:notice] = "Your order has been created"
      redirect_to orders_path
    else
      @title = "Order Form"
      render 'new'
    end
  end 
end

The issue is in my orders view:

<% for member in @order.members %>
  This displays 3 times but the information below doesn't
  <% fields_for "...", member do |member_form| %>
    <p>
      Name: <%= member_form.text_field :name %>
    </p>
  <% end %>
<% end %>

For some odd reason the information in the fields for tag won’t even display once. Am I missing something?

If you find out what I am doing wrong, can you please explain it to me because I am new to rails.

Thanks in advance!

  • 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-23T09:00:47+00:00Added an answer on May 23, 2026 at 9:00 am

    The block given to a fields_for call on a collection will be repeated for each instance in the collection, essentially creating its own loop, so you don’t really need to write your own explicit loop “for member in @order.members”. Further, you can leverage nested_attributes functionality to enable saving of associated members directly with @order.save:

    class Order < ActiveRecord::Base
      has_many :members 
      accepts_nested_attributes_for :members
    end
    
    class Member < ActiveRecord::Base
      belongs_to :order
    end
    

    In the view:

    <%= form_for @order do |order_form| %>
      ...
      <%= order_form.fields_for :members do |member_form| %>
        Name: <%= member_form.text_field :name %>
      <% end %>
    <% end %>
    

    And I think your controller create method should work as you have it.

    See the API docs for fields_for, especially the One-to-many subsection.

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

Sidebar

Related Questions

I have one grails application.In that I have one model class named Book. From
I have a model named Aggelia (it's greek for classified ad) and have set
Let's say I have this model named Product with a field named brand .
I have a such model named Foo: class Foo(models.Model): name = models.CharField() entry =
I have a controller/model hypothetically named Pets. Pets has the following declarations: belongs_to :owner
I have a books model with a date type column named publish_date. On my
I have a Section model, where a Section can be a parent of another
I have a table name BRANDS. I have another table named MODELS. The tables
I have separate apps with a foreign key from a model in one model
Hi I have a named_scope in my User model as following. named_scope :by_gender, lamdba

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.