KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 gett
Tags (comma-separated)
Save Edits
Cancel