Guest User

Untitled

a guest
May 16th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. I am ussing attribute_fu for multiple forms.
  2.  
  3. But, if I edit a Story and then add a new Play and add multiple Sounds to that new, unsaved Play, they all have an ID of "-1":
  4. story[play_attributes][new][-1][sound_attributes][new][-1][name]
  5.  
  6. And because of that only one of them is actually passed on as params and saved.
  7.  
  8. If I save my Play first, they will get fine numbering, -1, -2, -3.
  9.  
  10. ## models
  11. class Story
  12. has_many :plays, :attributes => true
  13.  
  14. class Play
  15. has_many :sounds, :attributes => true
  16.  
  17. ## story/edit.html.erb
  18. <% form_for :story, :url => { :action => 'update', :id => @story } do |f| %>
  19. <div id="plays">
  20. <%= f.render_associated_form(@story.plays) %>
  21. </div>
  22. <% end %>
  23.  
  24. ## story/_play.html.erb
  25. <div class="sounds">
  26. <%= f.render_associated_form(play.sounds) %>
  27. </div>
  28. <%= f.add_associated_link('Ny route', play.sounds.build, :expression => "$(this).previous('.sounds')") %>
  29.  
  30. ## story/_sound.html.erb
  31. <div class="sounds">
  32. <%= f.render_associated_form(play.sounds) %>
  33. </div>
  34. <%= f.add_associated_link('Ny lyd', play.sounds.build, :expression => "$(this).previous('.sounds')") %>
Add Comment
Please, Sign In to add comment