I've got an Ember app running a Rails API back-end, and I'm experiencing a weird problem between the two. I want the Message model data stored in the API to send up the stack to Ember. I've seeded the database with a couple messages built to match this migration:
class CreateMessages < ActiveRecord::Migration[5.0]
def change
create_table :messages do |t|
t.text :body
t.boolean :flagged
t.timestamps
end
end
end
Plus a serializer looking like this:
class MessageSerializer < ActiveModel::Serializer
attributes :id, :body, :flagged, :created_at, :updated_at
end
On the Ember side, my model is setup like so:
import DS from 'ember-data';
export default DS.Model.extend({
body: DS.attr('string'),
flagged: DS.attr('boolean'),
createdAt: DS.attr('date'),
updatedAt: DS.attr('date')
});
Ember shows both the flagged and body params just fine, but it only returns undefined
for the createdAt
and updatedAt
. By checking the Rails console, a quick test for the first Message returns something like this:
message.as_json
=> {"id"=>1, "body"=>"Etsy actually four dollar toast seitan. Schlitz twee kale chips pork belly franzen tote bag.", "flagged"=>true, "created_at"=>Wed, 02 Mar 2016 21:33:55 UTC +00:00, "updated_at"=>Wed, 02 Mar 2016 21:33:55 UTC +00:00}
I've seen some references on GitHub that do this more or less exactly, and I can't figure out where things have gone off. Any help appreciated!
Aucun commentaire:
Enregistrer un commentaire