Nested form and AngularJS, duplicated entities

Hello!

In my app i have a model Adventure, which has many Quests (and has “accepts_nested_attributes_for :quests, :allow_destroy => true” ). My form for adventure looks like this:

<%= form_for(@adventure) do |f| %> <% if @adventure.errors.any? %>

<%= pluralize(@adventure.errors.count, "error") %> prohibited this adventure from being saved:

    <% @adventure.errors.full_messages.each do |msg| %>
  • <%= msg %>
  • <% end %>
<% end %>

<%= f.hidden_field :is_special_event, :value => @is_special %>

<% unless @is_special %> Minimal player level
<%= f.number_field :minimal_level %> <% end %>
Name:
<%= f.text_field :name, :id => 'adv_name' %>
Description
<%= f.text_area :description, :id => 'adv_desc' %>
<br/><h2>Story</h2>
<div id="quests" ng-controller="QuestsController" ng-init="quests = <%= @adventure.quests.to_json %>">

  <div ng-repeat="quest in quests">
  	<%= render 'quest_fields' %>
  </div>

  <a href="#quest" class="new-quest" ng-click="add()">New +</a>

</div>
<%= f.submit 'Save', :class => 'submit-btn' %>
<% end %>

And the _quest_feilds.html.erb file

<%= hidden_field_tag 'adventure[quests_attributes][{{quest_index}}][order]', :value => '{{$index}}' %>


Title:
<%= text_field_tag ‘adventure[quests_attributes][{{quest_index}}][title]’, ‘{{quest.title}}’, :size => 150, id: ‘quest_{{$index}}title’ %>
Description
<%= text_area_tag ‘adventure[quests_attributes][{{quest_index}}][description]’,‘{{quest.description}}’, :cols => 107, :rows => 10, id: 'quest
{{$index}}_description’ %> And the problem is, when i’m trying to update any Adventure, instead of updating the quests, it keeps old records and is simply adding modified ones. So, instead of two records, when i’ll modify the adventure, i have four records. Does anybody have an idea ?

Thanks in advance!