Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am ussing attribute_fu for multiple forms.
- 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":
- story[play_attributes][new][-1][sound_attributes][new][-1][name]
- And because of that only one of them is actually passed on as params and saved.
- If I save my Play first, they will get fine numbering, -1, -2, -3.
- ## models
- class Story
- has_many :plays, :attributes => true
- class Play
- has_many :sounds, :attributes => true
- ## story/edit.html.erb
- <% form_for :story, :url => { :action => 'update', :id => @story } do |f| %>
- <div id="plays">
- <%= f.render_associated_form(@story.plays) %>
- </div>
- <% end %>
- ## story/_play.html.erb
- <div class="sounds">
- <%= f.render_associated_form(play.sounds) %>
- </div>
- <%= f.add_associated_link('Ny route', play.sounds.build, :expression => "$(this).previous('.sounds')") %>
- ## story/_sound.html.erb
- <div class="sounds">
- <%= f.render_associated_form(play.sounds) %>
- </div>
- <%= f.add_associated_link('Ny lyd', play.sounds.build, :expression => "$(this).previous('.sounds')") %>
Add Comment
Please, Sign In to add comment