0
votes

I've got a rails app where I'm linking fields across two databases. The database stuff all seems to be fine.

However, I have one form where I am mapping a description from the remote database to a product in the local database.

The form the used to create the product and select the description works fine

#_form.rb
 semantic_form_for @products do |f| 

   f.input :name
   semantic_fields_for :description_maps do |description|
     description.input :desciption_map_id, :input_html=>{:name=>"product[description_map][description_id]}, :collection => @descriptions
   end
 end

#product.rb 
class Product < ActiveRecord::Base
  attr_accessible :name, :description_map_attributes, :description_map

  has_one :description_map

  accepts_nested_attributes_for :description_map

when I submit the form, I get an error

DescriptionMap(#...) expected, got ActiveSupport::HashWithIndifferentAccess(#othernumber)

I can't seem to figure out why this is happening.

the parameters being posted look fine

"product"=>{"name"=>"test name", 
"description_map"=>{"description_id"=>"1"}}

2
your are not using correctly the nested model. Did you try to do f.fields_for :description_maps ?apneadiving
I'm using formtastic, so it is semantic_fields_for, that is correct.pedalpete
Well ok... And f.semantic_field_for or something like that? You have to nest your form...apneadiving

2 Answers

1
votes

turns out this was an issue with how formtastic was naming the description map. In the question, i had specified

 description.input :desciption_map_id, :input_html=>{:name=>"product[description_map][description_id]}, :collection => @descriptions

but the 'description_map' needed to be 'description_map_attributes' like this

 description.input :desciption_map_id, :input_html=>{:name=>"product[description_map_attributes][description_id]}, :collection => @descriptions

Hopefully this answer helps somebody else having the same issue.

0
votes

You should use: :description_map (without "S") cause is a has_on relation

semantic_fields_for :description_map do |description|
  description.input :desciption_map_id, :input_html=>{:name=>"product[description_map]      [description_id]}, :collection => @descriptions

end