I have Record & Category model:
class Record < ActiveRecord::Base
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :records
end
The Category model has a name field which should be used for display. I am using ng-repeat to display the records, the 'record.category.name' causes my page to break:
<tr ng-repeat="record in records">
<td>{{record.category.name)}}</td>
<td>{{record.description}}</td>
<td>{{record.created_at | date:'medium'}}</td>
</tr>
How can I properly retrieve the 'record.category' so that the 'name' field is available as I have above? Using ngResource thus far has not populated the associations.
I am retrieving the Record model using ngResource:
var Record = $resource('/records/:recordId', {
recordId:'@id',
format: 'json'
}, {
'save': {
method: 'PUT'
},
'create': {
method: 'POST'
}
});
Record.query({
account_id: $routeParams.accountId
}, function(results) {
return $scope.records = results;
});
How can I retrieve this model in AngularJS so that the association data are available for display as well?
Any help is appreciated.
Edit:
index.json.jbuilder
json.array! @records, partial: 'record', as: :record
_record.json.jbuilder
json.(record, :id, :account_id, :user_id, :amount, :date, :description, :is_expense, :category_id, include: [:category])