Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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 主干和轨道取数_Ruby On Rails_Ruby_Json_Ruby On Rails 3_Backbone.js - Fatal编程技术网

Ruby on rails 主干和轨道取数

Ruby on rails 主干和轨道取数,ruby-on-rails,ruby,json,ruby-on-rails-3,backbone.js,Ruby On Rails,Ruby,Json,Ruby On Rails 3,Backbone.js,因此,我使用model.fetch引入了一个模型 那个模型有一个集合。json包含一个数组(stops)。 模型中的集合正被数组覆盖,因为model.fetch返回的json包含该集合。这有什么办法吗 App.Models.Itinerary = Backbone.Model.extend({ url: '', ID: "", Name: "", stops: new App.Collections.StopCollection(), 然后我调用window.i

因此,我使用model.fetch引入了一个模型

那个模型有一个集合。json包含一个数组(stops)。 模型中的集合正被数组覆盖,因为model.fetch返回的json包含该集合。这有什么办法吗

App.Models.Itinerary = Backbone.Model.extend({
    url: '',
    ID: "",
    Name: "",
    stops: new App.Collections.StopCollection(),
然后我调用window.investure.fetch()

和stops现在是一个数组(具有正确的数据)

我得到的回报是

(模型)

(收集)


您的控制器方法在Rails中看起来像什么?@BrendanBenson
def show inventary=inventary.find(params[:id])render json:inventary end
,它使用inventary.rb
def as_json(option={})super({id:self.id,Name:self.Name,include:[:stops]})结束
我的意思是我的json回来了,就像我猜的那样?Just backbone.js就像一个数组,用数组覆盖属性stops(类型为StopCollection())。
{"ID":"7cd9dcdc-54f1-4704-a8be-393d67559b7e","Name":"China","stops":
    [{"ID":"1","Name":"Jordan Stop","Notes":"Ayo Notes!","OrderNumber":null},
{"ID":"5","Name":"Another Jordan Stop","Notes":"Aya Notes :-!","OrderNumber":null}]}