我有一个董事会模型,其category_id代表类别父类,即一个类别有很多董事会。 我有一个以下的红宝石模型
应用程序/模型/ board.rb
class Board < ActiveRecord::Base
attr_accessible :description, :name, :open, :members, :category_id
belongs_to :category
end
我想通过在骨干模板标签标签中使用category_id(可访问)来获取类别对象。如果我访问类别对象,我在标签标签中变为空。
<div class="myNavigation">
<nav class="vertical">
<ul>
<% boards.each(function (board) { %>
<li>
<% debugger; %>
<label for="home"><%= board.escape("category_id") %></label>
<input type="radio" checked="true" name="verticalMenu" id="home" />
<div>
</div>
</li>
<% }); %>
</ul>
</nav>
</div>
&#13;
以下是很多代码,如果需要更多代码,我会发布。
骨干模型:
应用程序/资产/ Javascript角/模型/ board.js
Kanban.Models.Board = Backbone.RelationalModel.extend({
urlRoot: "/api/boards",
relations: [{
type: Backbone.HasMany,
key: "lists",
relatedModel: "Kanban.Models.List",
collectionType: "Kanban.Collections.Lists",
reverseRelation: {
key: "board"
}
},{
type: Backbone.HasMany,
key: "users",
relatedModel: "Kanban.Models.User",
collectionType: "Kanban.Collections.Users"
}]
});
类别模型:
应用程序/资产/ Javascript角/模型/ category.js
Kanban.Models.Category = Backbone.RelationalModel.extend({
urlRoot: "/categories",
relations: [{
type: Backbone.HasMany,
key: "boards",
relatedModel: "Kanban.Models.Board",
collectionType: "Kanban.Collections.Boards",
reverseRelation: {
key: "category"
}
}]
});
应用程序/视图/类别/ index.rabl
collection @categories
attributes :id, :title, :description