Last active
December 19, 2015 20:49
-
-
Save dustinfarris/6015704 to your computer and use it in GitHub Desktop.
Pre-populate children and grandchildren when a parent is created. The app has a set of bridge—the card game—Exercises, each Exercise consisting of 8 Hands, each Hand having an Answer for each Row within the Exercise's associated Situation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.ExercisesNewController = App.ObjectController.extend | |
create: -> | |
situation_id = $('#id_situation').val() | |
situation = App.Situation.find(situation_id) | |
@content.set 'situation', situation | |
rows = situation.get('rows') | |
@content.save().then => | |
for i in [1..8] | |
hand = App.Hand.createRecord | |
exercise: @content | |
order: i | |
hand.save().then (hand) => | |
rows.forEach (row) -> | |
answer = App.Answer.createRecord | |
row: row | |
hand: hand | |
min: '' | |
mid: '' | |
max: '' | |
answer.save() | |
@store.commit() | |
@success "Exercise created!" | |
@transitionToRoute 'exercises.edit', @content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment