[英]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. 我的模型似乎在显示某个日期的正确信息(这称为Moment),但是当我尝试将数据保存到Rails后端时,“ null”会通过网络发送。 I'm using the ActiveModelAdapter, is there anything else I need to do to read/write dates?
我正在使用ActiveModelAdapter,我还需要做其他读取/写入日期的事情吗? Thanks!
谢谢!
Are you using Moment.js ? 您正在使用Moment.js吗? The best practice for formatting your dates with Moment is by registering a helper - see the guide here .
使用Moment格式化日期的最佳做法是注册一个助手- 请参阅此处的指南 。 An addon, eg ember-moment , can make this easier.
插件(例如ember-moment )可以使此操作更容易。
Your model itself shouldn't know about Moment - the date attached to your model should just be a Date object. 您的模型本身不应该知道Moment-附加在模型上的日期应该只是一个Date对象。 If you've declared
dateAttribute: DS.attr("date")
in your model, it should be serialized and transmitted appropriately by Ember Data. 如果您在模型中声明了
dateAttribute: DS.attr("date")
,则应该由Ember Data对其进行序列化和适当地传输。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.