At the moment the JSON in my rails API with ember front end app is formatting incorrectly for my images model as shown below.
This results in the ember Chrome tool showing the data for my Project_image as 'object Object' and project_id as 'null' which isn't very useful in my templates.
How can I format the JSON using Active_Model_Serializer to output the data correctly.
Current JSON Example:
{
"images":
[
{
"id":6,
"project_image":
{"project_image":
{"url":"/uploads/image/project_image/6/example_image.jpg"}
},
"project_id":8
}
]
}
Current image_serializer.rb
class ImageSerializer < ActiveModel::Serializer
attributes :id, :project_image, :project_id
end
Any help would be much appreciated! :)
Ember Models
Image
App.Image = DS.Model.extend({
project_image: DS.attr('string'),
project_id: DS.attr('number'),
project: DS.belongsTo('project')
});
Project
App.Project = DS.Model.extend({
client: DS.attr('string'),
tags: DS.attr('string'),
description: DS.attr('string'),
start_date: DS.attr('string'),
end_date: DS.attr('string'),
images: DS.hasMany('image')
});
Rails Models
Image
class Image < ActiveRecord::Base
belongs_to :project
mount_uploader :project_image, ImageUploader
end
Project
class Project < ActiveRecord::Base
has_many :images, :dependent => :destroy
accepts_nested_attributes_for :images, allow_destroy: true
end
All Project model data loads correctly, the error is only with the images model.