Created
January 13, 2013 04:56
-
-
Save tatey/4522385 to your computer and use it in GitHub Desktop.
Rails ERB template for http://jsfiddle.net/tatejohnson/vLhNb/. Adding and removing children to a Rails nested form with AngularJS.
This file contains hidden or 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
<h1>New Plan</h1> | |
<div ng-app> | |
<%= form_for @plan do |form| %> | |
<div ng-controller="PollCtrl" ng-init="polls = <%= @plan.polls.to_json %>"> | |
<div ng-repeat="poll in polls"> | |
<%= form.fields_for :polls, Poll.new, child_index: '{{$index}}' do |poll_form| %> | |
<%= poll_form.text_field :title, id: 'plan_poll_{{$index}}', value: '{{poll.title}}' %> | |
<% end %> | |
<a href="#" ng-click="remove($index)" ng-show="isRemovable()">Remove</a> | |
</div> | |
<a href="#" ng-click="add()">Add</a> | |
</div> | |
<% end %> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to set an id on the text field, otherwise all your text fields will have
plan_polls_attributes____index___title
as their id. If you don't care, then you can omit it.