使用simple_form格式化日期输入 [英] Formatting a date input using simple_form
本文介绍了使用simple_form格式化日期输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据库中有一个日期
类型字段。
I have a date
type field in my database.
这是我使用的视图代码:
Here's the view code I'm using:
# Using 'as: :string' to avoid those three dropdowns rails generates.
= f.input_field :start_date, as: :string, class: 'form-control datepicker'
当保存日期时,我使用一个jquery插件来显示一个日历,并以下列日期写入: 11/05/2013
。
When saving a date I use a jquery plugin that shows a calendar and writes in a date like: 11/05/2013
.
但编辑同一条记录时,输入的值为 2013-05-11
。
But when editing the same record, the input is populated with a value 2013-05-11
.
我如何做到这样simple_form实际上尊重我在 en.yml
中定义的日期格式?
How can I make it so simple_form actually respects my date format defined in en.yml
?
推荐答案
这是你需要的:
f.input :my_date,
:as => :string,
:input_html => { :value => localize(f.object.my_date) }
PS:这是google中的第一个链接搜索:)
PS : This was the first link in google search :)
这篇关于使用simple_form格式化日期输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文