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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:57:06+00:00 2026-06-18T10:57:06+00:00

I’m trying to create a nested group for customer profiles with multiple billing addresses

  • 0

I’m trying to create a nested group for customer profiles with multiple billing addresses and postal addresses.When I browse to the customer profile form I see the fields for the Customer profile form but I do not see any fields for the Billing Address form or Postal Address form. Any ideas? my controller, models and view are below.

The goal is to have one customer profile which can multiple billing addresses and multiple postal addresses.

customer profile model:

    class CustomerProfile < ActiveRecord::Base
        #These entries are required to create a nested model form (multiple models in one form)
        validates_presence_of :customerNumber
        validates_uniqueness_of :customerNumber


        has_many :billing_addresses, :dependent => :destroy
        has_many :postal_addresses,  :dependent => :destroy

        accepts_nested_attributes_for :billing_addresses, :reject_if => lambda { |a| a[:content].blank?}, :allow_destroy => true
        accepts_nested_attributes_for :postal_addresses, :reject_if => lambda { |a| a[:content].blank?}, :allow_destroy => true
    end

billing address model:

    class BillingAddress < ActiveRecord::Base
        belongs_to :customer_profile
        attr_protected :customerNumber
    end

postal address model:

    class PostalAddress < ActiveRecord::Base
        belongs_to :customer_profile
        attr_protected :customerNumber
    end

customer profile controller:

    def new
        @customer_profile = CustomerProfile.new

        respond_to do |format|
          format.html # new.html.erb
          format.json { render json: @customer_profile }
        end
    end


    def create
        @customer_profile = CustomerProfile.new(params[:customer_profile])

        respond_to do |format|
          if @customer_profile.save
            format.html { redirect_to @customer_profile, notice: 'Customer profile was successfully created.' }
            format.json { render json: @customer_profile, status: :created, location: @customer_profile }
          else
            format.html { render action: "new" }
            format.json { render json: @customer_profile.errors, status: :unprocessable_entity }
          end
        end
    end

customer profile form:

    <br />
    <h3>Add new customer profile with Billing and Postal Address</h3>
    <br />
    <h4> Customer Profile </h4>
    <%= form_for @customer_profile do |f| %>
        <div class="field">
            <%= f.label :customerNumber %><br />
            <%= f.text_field :customerNumber %>
        </div>

        #.... a few other fields removed to keep this short

    <br />
        <h4> Billing Address </h4>
        <%= f.fields_for :billing_addresses do |b| %>

            <div class="field">
                <%= b.label :addressLine1 %><br />
                <%= b.text_field :addressLine1 %>
            </div>

        #.... a few other fields removed to keep this short

        <% end %>

        <br />
        <h4> Postal Address </h4>
        <br />
        <%= f.fields_for :postal_addresses do |p| %>

            <div class="field">
                <%= p.label :addressLine1 %><br />
                <%= p.text_field :addressLine1 %>
            </div>

        #.... a few other fields removed to keep this short

        <br />
        <% end %>
        <%= f.submit %>
    <% end %>
  • 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-18T10:57:08+00:00Added an answer on June 18, 2026 at 10:57 am

    The fields_for will show fields for billing_addresses that are children of the customer_profile. If this is a new object, you’ll either need to add one or more, or – add the appropriate fields through JavaScript. You may want to to both, so there’s an empty fields when they get there, then they can add more after.

    You can do a @customer_profile.billing_addresses.build to have an empty one when the form is rendered.

    Do you know how to add and remove fields via javascript? It’s covered well on railscasts.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.