我按照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