I have 2 models, Category and LineItemTypes
There are already plenty existing of both, it is now a requirement for
them to be associated. Being many LineItemTypes for every Category.
I have added accepts_nested_attributes_for :line_item_types on Category
I've tried using a hidden_field on a form to create a list of existing
associated LineItemTypes:
- form_for @category do |form|
%ul#categorised
- form.fields_for :line_item_types do |line_item_types|
-categorised.each do |l|
%li
=l.description
=line_item_types.hidden_field :category_id
=form.submit
If I add an item to that list, I get errors saying that a LineItemType
for that Category can't be found. I thought
accepts_nested_attributes_for would add the association if it doesn't
exist. Or is it only for 'creating' new records and modifying existing
relationships, not creating new relationships.
a.update_attributes({:line_item_types_attributes => [{:id => 2767}, {:id
=> LineItemType.find(2).id}]})
ActiveRecord::RecordNotFound: Couldn't find LineItemType with ID=2 for
Category with ID=1
Any ideas without having to write something to traverse the resulting
form params and create the associations? Or an even easier way to
achieving this? I have an existing association with
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.