我按照https://github.com/coshx/techlunches/tree/fdb70ff65997f9中的教程创建了一个普通的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_id')
1
>> Presenter.find(1)('name')
Ben但是,这行不起作用。
>> Presentation.find(1)('presenter')
undefined发布于 2013-06-25 00:28:38
首先,资源是异步的--它们从后端请求数据。因此,它应该是Presentation.find 1, (presentation) -> presentation('presenter')。
需要注意的另一件事是,这样的请求将返回原始的JSON数据。如果您想要关联实例,请使用presentation.presenter。
https://stackoverflow.com/questions/17280336
复制相似问题