ruby on rails - Fields For Not Working for Has Many Association -


i'm building form model , having trouble developing associated model forms form.

the error i'm receiving:

undefined method `tradie_id' #<activerecord::associations::collectionproxy::activerecord_associations_collectionproxy_tradiecategory:0xd0f9d78> 

the form code looks like:

= form_for @data[:tradie], url: { action: "update_tradie" } |tradie|    # doesn't work   = tradie.fields_for :tradie_categories, @data[:tradie].tradie_categories |category|     = category.text_field :tradie_id    # fields_for   = tradie.fields_for :tradie_locations, @data[:tradie].tradie_locations |location|     = location.text_field :address 

the tradie model has has_many relationship tradiecategory model , tradiecategory model has belongs_to relationship tradie. verified tradiecategory has field tradie_id.

in form above, @data[:tradie] equals instance of tradie model. whenever call tradie_categories or tradie_locations calling associated model data of tradiecategory , tradielocation.

finally, in view code, if run = @data[:tradie].tradie_categories.to_a, i'm returned on html page

[#<tradiecategory id: 2, tradie_id: 2, category_id: 1, created_at: "2013-09-08 19:50:10", updated_at: "2013-09-08 19:50:10">] 

i have no idea wrong this. what's problem , how fix this?

did add accepts_nested_attributes_for :tradie_categories in tradie model?


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -