I have a board model which has category_id which is representing category parent class i.e. one category has many boards. I have a following ruby model
app/models/board.rb
class Board < ActiveRecord::Base
attr_accessible :description, :name, :open, :members, :category_id
belongs_to :category
end
Only I want to get category object by using category_id (which is accessible) in backbone template label tag. I am getting null in label tag if I access category object.
<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>
Following is a lot of code, and if some more needed i will post.
backbone model:
app/assets/javascripts/model/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"
}]
});
category model:
app/assets/javascripts/model/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"
}
}]
});
app/views/categories/index.rabl
collection @categories
attributes :id, :title, :description