How do I create a parent from child in Rails? <p>In my app I'm receiving this error.</p> <blockquote> <p>Couldn't find Vendor with ID=1 for InventoryItem with ID=</p> </blockquote> <p>InventoryItem.rb</p> <pre><code>belongs_to :vendor accepts_nested_attributes_for :vendor </code></pre> <p>Vendor.rb</p> <pre><code>has_many :inventory_items </code></pre> <p>_form.html.erb</p> <pre><code>&lt;%= simple_nested_form_for @inventory_item, :html =&gt; {:class =&gt; 'form-inline' } do |f| %&gt; &lt;h2&gt;Inventory Data&lt;/h2&gt; &lt;%= f.input :name, :input_html =&gt; {:autocomplete =&gt; :off, :placeholder =&gt; 'Item Name' }%&gt; &lt;%= f.input :id, :as =&gt; :hidden %&gt; &lt;%= f.simple_fields_for :vendor do |v| %&gt; &lt;%= v.input :name, :label =&gt; 'Vendor name', :input_html =&gt; {:autocomplete =&gt; :off, :placeholder =&gt; 'Vendor Name' } %&gt; &lt;%= v.input :id, :as =&gt; :hidden %&gt; &lt;% end %&gt; &lt;% end %&gt; ----snip---- </code></pre> <p>My parameters hash comes out accordingly</p> <pre><code>{"utf8"=&gt;"✓", "authenticity_token"=&gt;"ZY9fum4XGStTMNbpRQxrzmP7PT3A6BUU+wOymV0fZ/c=", "inventory_item"=&gt;{"name"=&gt;"testing", "id"=&gt;"7678", "vendor_attributes"=&gt;{"name"=&gt;"test", "id"=&gt;"1"}, "item_instances_attributes"=&gt;{"0"=&gt;{"barcode"=&gt;"", "funding_source"=&gt;"", "serial"=&gt;"", "version"=&gt;"", "website_id"=&gt;"", "item_type"=&gt;"Retail", "type_of_at"=&gt;"Vision", "os"=&gt;"Mac", "registration_key"=&gt;"", "dealer_price"=&gt;"", "retail_price"=&gt;"", "reuse_price"=&gt;"", "estimated_current_purchase_price"=&gt;"", "cost_to_consumer_for_loan"=&gt;"", "repair_status"=&gt;"Working", "date_reviewed"=&gt;"10-15-2012", "qr_url"=&gt;"", "location"=&gt;"", "restrictions"=&gt;"", "notes"=&gt;""}}}, "commit"=&gt;"Create Inventory item"} </code></pre> <p>inventory_items_controller.rb</p> <pre><code>def create params[:inventory_item].delete(:estimated_dealer_price) @inventory_item = InventoryItem.create(params[:inventory_item]) @inventory_item.name = inventory_item.name.downcase if inventory_item.save redirect_to(inventory_items_path, :notice =&gt; "Item created.") else render 'new' end end </code></pre> <p>The controller is receiving the id and attempting to find the right vendor (which exists), has issues when left to the built-in rails methods for finding the vendor and building the relationship.</p> <p>The input for vendor name is an autocomplete which assigns the id to the hidden id field.</p> <p>possible solutions:</p> <ol> <li>Handle manually in the controller, fetching the id and building the relationship</li> <li>change the form so that the inventory_item.vendor.name autocompletes inventory_item.vendor_id and strip the name if an id is provided</li> <li>fix something I'm missing?</li> </ol>