简体   繁体   中英

How do you save dates from Ember to a Rails backend?

My model seems to be showing the right information for a date (which it's calling a Moment), but when I try to save data to my rails backend, "null" is sent across the wire. I'm using the ActiveModelAdapter, is there anything else I need to do to read/write dates? Thanks!

Are you using Moment.js ? The best practice for formatting your dates with Moment is by registering a helper - see the guide here . An addon, eg ember-moment , can make this easier.

Your model itself shouldn't know about Moment - the date attached to your model should just be a Date object. If you've declared dateAttribute: DS.attr("date") in your model, it should be serialized and transmitted appropriately by Ember Data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM