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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:48:34+00:00 2026-05-24T13:48:34+00:00

I am still having problems with nested forms. Here is my form code: <%=

  • 0

I am still having problems with nested forms. Here is my form code:

<%= form_for @account do |f| %>

<%= f.label :account_type %><br />
<%= f.text_field :account_type %><br />

    <%= f.fields_for :organizations do |builder| %>
        <%= builder.label :name %><br />
        <%= builder.text_field :name %><br />
        <%= builder.label :website %><br />
        <%= builder.text_field :website %><br />

        <%= f.fields_for :locations do |builder| %>
            <%= builder.label :phone %><br />
            <%= builder.text_field :phone %><br />
            <%= builder.label :toll_free_phone %><br />
            <%= builder.text_field :toll_free_phone %><br />
            <%= builder.label :fax %><br />
            <%= builder.text_field :fax %><br />
        <% end %>
    <% end %>

<%= f.submit "Add account" %>
<% end %>

The Account model:

class Account < ActiveRecord::Base

has_many :organizations

accepts_nested_attributes_for :organizations
end

The Organization model:

class Organization < ActiveRecord::Base

belongs_to :account

has_many :locations

accepts_nested_attributes_for :locations
end

And the Location model:

class Location < ActiveRecord::Base

belongs_to :organization

end

And lastly, the Accounts Controller:

class AccountsController < ApplicationController

def new
    @account = Account.new
    organization = @account.organizations.build
    organization.locations.build

    @header = "Create account"
end

def create
    @account = Account.new(params[:account])
    if @account.save
        #handle success
    else
        render 'new'
    end
end
end

Here is the error I am getting:

ActiveRecord::UnknownAttributeError in AccountsController#create

unknown attribute: locations
Rails.root: C:/Documents and Settings/Corey Quillen/My       
Documents/rails_projects/shop_manager

Application Trace | Framework Trace | Full Trace
app/controllers/accounts_controller.rb:12:in `new'
app/controllers/accounts_controller.rb:12:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"xuZLSP+PSjdra3v51nIkJYZeXRM0X88iF135hPlp4sc=",
 "account"=>{"account_type"=>"Company",
 "organizations_attributes"=>{"0"=>{"name"=>"Atlas",
 "website"=>"www.atlas.com"}},
 "locations"=>{"phone"=>"555-555-5555",
 "toll_free_phone"=>"800-555-5555",
 "fax"=>"512-555-5555"}},
 "commit"=>"Add account"}

Any help with this will be greatly appreciated. I have been looking at this now for a couple of hours.

  • 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-24T13:48:34+00:00Added an answer on May 24, 2026 at 1:48 pm

    You should use new builder in nested form for nested nested form :)) :

    <%= form_for @account do |f| %>
    
    <%= f.label :account_type %><br />
    <%= f.text_field :account_type %><br />
    
        <%= f.fields_for :organizations do |builder| %>
            <%= builder.label :name %><br />
            <%= builder.text_field :name %><br />
            <%= builder.label :website %><br />
            <%= builder.text_field :website %><br />
    
            <%= builder.fields_for :locations do |lb| %>
                <%= lb.label :phone %><br />
                <%= lb.text_field :phone %><br />
                <%= lb.label :toll_free_phone %><br />
                <%= lb.text_field :toll_free_phone %><br />
                <%= lb.label :fax %><br />
                <%= lb.text_field :fax %><br />
            <% end %>
        <% end %>
    
    <%= f.submit "Add account" %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still having problems with figuring out how to create winforms in a
I'm having problems with my ASP.NET web forms system. It worked on our test
I'm still having problems to write lambda expressions that should create some object and
I'm still having problems with loading the style sheet for these pages. Works fine
ive had a few questions on this subject, still having problems. I want to
Yesterday I asked this post , but I am still having problems when I
I recently learned about endianness and am still having difficulty identifying problem areas. Here
I am still having problems with this so I can going to ask for
I'm still having problems with a custom tag and JSP. I've implemented a suggestion
Been through my textbook, but I'm still having problems with catching an inner exception

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.