Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails AngularJS中的嵌套表单字段_Ruby On Rails_Json_Angularjs_Nested Forms - Fatal编程技术网

Ruby on rails AngularJS中的嵌套表单字段

Ruby on rails AngularJS中的嵌套表单字段,ruby-on-rails,json,angularjs,nested-forms,Ruby On Rails,Json,Angularjs,Nested Forms,我正在开发一个带有远程Rails后端的AngularJS应用程序,用于注册体育赛事。除了注册为一名跑步者外,用户还应该能够提交4名跑步者的接力队注册 Rails后端结构: class Relay < ActiveRecord::Base has_many :registrations accepts_nested_attributes_for :registrations end class Registration < ActiveRecord::Base belon

我正在开发一个带有远程Rails后端的AngularJS应用程序,用于注册体育赛事。除了注册为一名跑步者外,用户还应该能够提交4名跑步者的接力队注册

Rails后端结构:

class Relay < ActiveRecord::Base
  has_many :registrations
  accepts_nested_attributes_for :registrations
end

class Registration < ActiveRecord::Base
  belongs_to :relay
end

class API::RelaysController < API::BaseController
  def create
    @relay = Relay.new(relay_params)
    if @relay.save
      render json: @relay, status: :created#, location: @relay
    else
      render json: @relay.errors, status: :unprocessable_entity
    end
  end
end
relay-create.html:

<form name="form" ng-submit="submit()" class="form-horizontal" novalidate>
  <div ng-repeat="registration in relay.registrations_attributes" ng-form="registration_form" class="well">
    ...
    <div class="form-group">
      <label class="control-label col-sm-4">
        Firstname
      </label>
      <div class="input-group col-sm-7">
        <input class="form-control" ng-model="registrations_attributes.runner_firstname" type="text">
      </div>
    </div>
    ...
  </div>
</form>

...
名字
...


我需要遵循哪些步骤才能获得一个表单,其中嵌套字段在AngularJS中运行,就像我在Rails中创建的表单一样?不确定嵌套是什么意思,是否有错误?在Rails的中继表单中,我为每个相应的注册使用了一个fields_标记,这意味着当用户提交一个新的中继团队时,四个注册(每个运行者)理想情况下,从angular提交到rails后端的json应该是:{“relay”:{name:“relay XYZ”,registrations_属性[{runner_firstname:“First runner”…},{runner_firstname:“Second runner”…},等等。]}
rilaServices.factory('Registration', ['$resource',
  function($resource){
    return $resource('http://localhost:3000/api/registrations/:id', { id: "@id" }, {
      'create':  { method: 'POST' }
    });
  }
 ]);

rilaServices.factory('Relay', ['$resource',
  function($resource){
    return $resource('http://localhost:3000/api/relays/:id', { id: "@id" }, {
      'create':  { method: 'POST' }
    });
  }
 ]);
<form name="form" ng-submit="submit()" class="form-horizontal" novalidate>
  <div ng-repeat="registration in relay.registrations_attributes" ng-form="registration_form" class="well">
    ...
    <div class="form-group">
      <label class="control-label col-sm-4">
        Firstname
      </label>
      <div class="input-group col-sm-7">
        <input class="form-control" ng-model="registrations_attributes.runner_firstname" type="text">
      </div>
    </div>
    ...
  </div>
</form>