Rails 日期字段格式错误
我有一个输入字段,用于捕获表单中的日期
<%= f.text_field :from_date, :style => 'width:80px;' %>
用户按以下格式输入日期 MM/DD/YYYY。但是,当模型中存在验证错误并且表单与输入的值一起显示给用户时,日期格式将转换为 YYYY-MM-DD HH:MM:SS UTC。当向用户显示表单时,我应该在哪里设置格式以显示 MM/DD/YYYY。
谢谢。
I have an input field that captures a date in my form
<%= f.text_field :from_date, :style => 'width:80px;' %>
The user enters the date in the following format MM/DD/YYYY. However, when there is a validation error in the model and the form is displayed back to the user with the entered values, the date format is converted to YYYY-MM-DD HH:MM:SS UTC. Where do I format this to show MM/DD/YYYY, when the form is displayed to the user.
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下 &用你的日期代替@date
<%= f.text_field :from_date, :style =>; '宽度:80px;',:值=>(@date.blank?)? '' : @date.strftime('%m/%d/Y') %>
Try following & put your date in place of the @date
<%= f.text_field :from_date, :style => 'width:80px;', :value=>(@date.blank?)? '' : @date.strftime('%m/%d/Y') %>