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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:11:08+00:00 2026-05-23T17:11:08+00:00

I am having some issues with nested models in a form, using Rails 3.1rc4.

  • 0

I am having some issues with nested models in a form, using Rails 3.1rc4.

I presently have models that look like this:

class Sale < ActiveRecord::Base
  attr_accessible :customer_id, :vehicle_id, :sale_date

  belongs_to :customer
  accepts_nested_attributes_for :customer
end

and

class Customer < ActiveRecord::Base
  attr_accessible :dealership_id, :first_name, :last_name, :address1, :email

  belongs_to :dealership

  has_many :sales
  has_many :vehicles, :through => :sales

end

I’ve obviously truncated these slightly, but all the important info is there.

I am attempting to set up a sale form that will also allow me to create a new customer, hence the accepts_nested_attributes_for :customer line in the sale model.

My form view looks like (again truncated, only the important part):

    <%= form_for @sale, :html => {:class => 'fullform'} do |f| %>

        <%= f.error_messages %>

        <%= field_set_tag 'Customer Details' do %>
            <% f.fields_for :customer do |builder| %>
                <%= builder.label :first_name %><br>
                <%= builder.text_field :first_name %>
            <% end %>
        <% end %>
    <% end %>

The problem I am having is that neither the text field nor the label for :first_name are showing up when the form is rendered – there is no error message, it just doesn’t appear.

I should mention that I have tried both with and without @sale.customer.build in the new method of my controller, but it seems to have had no effect.

Thanks!

Can anyone suggest what I am doing wrong?

EDIT: For the avoidance of doubt, my sales controller’s new method looks like:

def new
  @sale = Sale.new
  @sale.customer.build
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-05-23T17:11:09+00:00Added an answer on May 23, 2026 at 5:11 pm

    Add customer_attributes to your attr_accessible in the Sale model.

    Another mistake; Replace:

    <% f.fields_for :customer do |builder| %>
    

    With:

    <%= f.fields_for :customer do |builder| %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I am having some issues with using the OrderBy extension method on a LINQ
I am using Fluent NHibernate and having some issues getting a many to many
I'm having some weird issues with Xcode, and this is pretty much impossible to
We've been having some issues with a SharePoint instance in a test environment. Thankfully
I'm having some issues with producing an int matrix without creating memory leaks. I
We are having some issues getting SharePoint to work as we want it to.
I'm having some inheritance issues as I've got a group of inter-related abstract classes
We are having some performance issues with a page and I wanted to ask
I'm trying to experiment with xampp. After having some space issues, I wanted to

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.