简体   繁体   English

您如何将日期从Ember保存到Rails后端?

[英]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.

相关问题 您如何最好地处理带有日期的测试? - How do you best handle tests with dates? 你如何让 dataframe 匹配日期时间日期? - How do you make dataframe match datetime dates? 如何在数据库中保存将来的日期 - How to save future(!) dates in a database 从后端检索日期时,禁用日期不起作用 角度Datepicker - Disabled date not working when dates retrieved from backend | Angular Datepicker 您如何获取文件夹中所有文件的上次修改日期,并将其与特定日期进行比较? 的PHP - How do you get last modified dates of all files within a folder and compare it to a certain date? php 使用Shiny Table时,如何使日期以日期格式显示? - How do you get dates to show up in a date format when working with a Shiny Table? 当有两个日期时,如何从 Python 中的文件名中提取日期? 我如何转换为一年中的某一天? - How to extract dates from filename in Python when there are two dates? And how do I convert to day of year? 如何从日期列表中获取 max()? - How do I get max() from a list of dates? 如何防止javascript将我的日期转换为GMT? - How do I prevent javascript from converting my dates to GMT? 如何让 Python 从日期中提取工作日? - How do I get Python to extract weekdays from dates?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM