Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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 如何通过Joosy获取相关资源?_Ruby On Rails_Relationship_Joosy - Fatal编程技术网

Ruby on rails 如何通过Joosy获取相关资源?

Ruby on rails 如何通过Joosy获取相关资源?,ruby-on-rails,relationship,joosy,Ruby On Rails,Relationship,Joosy,我根据中的教程创建了一个香草joosy rails应用程序 rails和joosy端都有两个资源: # app/models/presenter.rb class Presenter < ActiveRecord::Base attr_accessible :email, :github_username, :name, :twitter_username has_many :presentations end # app/models/presentation.rb clas

我根据中的教程创建了一个香草joosy rails应用程序

rails和joosy端都有两个资源:

# app/models/presenter.rb
class Presenter < ActiveRecord::Base
  attr_accessible :email, :github_username, :name, :twitter_username

  has_many :presentations
end

# app/models/presentation.rb
class Presentation < ActiveRecord::Base
  attr_accessible :description, :title

  belongs_to :presenter
end

# app/assets/javascripts/techlunches/resources/presentation.js.coffee
# (next line needed because this file is loaded before presenter.js.coffee)
#= require techlunches/resources/presenter
class @Presentation extends Joosy.Resource.REST
  @entity 'presentation'
  @map 'presenter', @Presenter

# app/assets/javascripts/techlunches/resources/presenter.js.coffee
class @Presenter extends Joosy.Resource.REST
  @entity 'presenter'
  @map 'presentations', @Presentation
但是,这条线不起作用

>> Presentation.find(1)('presenter')
   undefined

首先,资源是异步的——它们从后端请求数据。因此,它应该是
Presentation.find 1,(Presentation)->Presentation('presenter')


另外需要注意的是,这样的请求将返回原始JSON数据。如果您要查找关联实例,请使用演示文稿。演示者首先,资源是异步的–它们从后端请求数据。因此,它应该是
Presentation.find 1,(Presentation)->Presentation('presenter')


另外需要注意的是,这样的请求将返回原始JSON数据。如果您要查找关联实例,请使用
presentation.presenter

presentation.find(1,函数(p){console.dir(p('presenter'));})
在本例中还显示了
未定义的
,因此当我切换到异步样式时,我看到了相同的结果。@BenTaitelbaum您的服务器响应什么?您是否将
presenter
包含在控制器/视图的JSON响应中?我只是将
presenter\u id
包含在JSON中,假设Joosy理解该约定。我是否需要显式地包含关联的资源?这可能是未来优化的一个领域,但目前您是否在rable、jbuilder或其他方面有偏好?Joosy总是对每个资源搜索发出唯一的HTTP请求。它试图确定服务器响应什么。所以,服务器有责任内联所有必需的关联
@map
是一种糖,可以帮助
对象的包装。如果您想发出子请求,实际上甚至不需要
@map
,只需为每个对象调用
find
两次即可。但你不应该。您只需使用
include
选项即可使用json
。但是我会推荐
jbuilder
。谢谢,我使用了它,尽管我无法使用
presentations.presenter('name')
Presentation.find(1,函数(p){console.dir(p('presenter');})
在本例中还显示了
未定义的
,因此当我切换到异步样式时,我看到了相同的结果。@BenTaitelbaum您的服务器响应什么?您是否将
presenter
包含在控制器/视图的JSON响应中?我只是将
presenter\u id
包含在JSON中,假设Joosy理解该约定。我是否需要显式地包含关联的资源?这可能是未来优化的一个领域,但目前您是否在rable、jbuilder或其他方面有偏好?Joosy总是对每个资源搜索发出唯一的HTTP请求。它试图确定服务器响应什么。所以,服务器有责任内联所有必需的关联
@map
是一种糖,可以帮助
对象的包装。如果您想发出子请求,实际上甚至不需要
@map
,只需为每个对象调用
find
两次即可。但你不应该。您只需使用
include
选项即可使用json
。但是我推荐使用
jbuilder
。谢谢,我使用了它,尽管我无法使用
演示文稿。演示者('name')
>> Presentation.find(1)('presenter')
   undefined