Date and Time Fields-rails中的时间标签

 下午解决了一个时间的问题.数据库表中有个字段borrow_time类型是date,用rails的脚手架生成的_form.html中使用了
<p><label for="borrow_equipment_borrow_time">借用时间</label><br/>
<%= date_select 'borrow_equipment', 'borrow_time' %></p>
这样生成的时间月份显示的是英文,这不符合客户的要求,所以要改成数字,经查找发现要添加:use_month_numbers => true,即
<p><label for="borrow_equipment_borrow_time">借用时间</label><br/>
<%= date_select( 'borrow_equipment', 'borrow_time',:use_month_numbers => true)  %></p>

下面是我查找的资料

date_select(:variable, :attribute, options)

datetime_select(:variable, :attribute, options)

select_date(date = Date.today, options)

select_day(date, options)

select_month(date, options)

select_year(date, options)

select_datetime(date = Time.now, options)

select_hour(time, options)

select_minute(time, options)

select_second(time, options)

select_time(time, options)

有两套date选择“饰件”(widgets)。第一套是date_select()和datetime_select(),它们创建用于“活动记录模型”的date和datetime属性的“饰件”。第二套,是select_xxx样变化,也用于没有“活动记录”支持的工作。图17.4显示了“动作”内的这些方法。

缺省地,select_xxx widget被给出date[xxx]样名字,所以在“控制器”内你可以用params[:date][:minute]访问分钟的选择。你可以使用:prefix选项修改来自date的前缀,并且你可以在方括号内使用:discard_type选项来禁止添加字段类型。:include_blank选项添加一个空的选项给列表。

select_minute()方法支持:minute_step => nn 选项。例如,设置它为15,将只列出0,15,30,45选项。

select_month()方法通常列出month名字。设置选项:add_month_numbers => true 来显示month 数字,或者设置选项:use_month_numbers => true 来只显示数字。

select_year()方法缺省地列出自当前年的五年。这可以使用:start_year=>yyyy和:end_year=>yyyy选项来修改。

date_select()和datetime_select()创建允许用户设置“活动记录模型”内selection lists的一个date(或datetime)的“饰件”。被存储于@variable.attribute内的date被用做缺省值。display包括用于year,month,day(hour,minute,second)的各个selection lists。The display includes separate selection lists for the year, month, day (and hour, minute, second). Select lists for particular fields can be removed from the display by setting the options :discard_month => 1, :discard_day => 1, and so on. Only one discard option is required—all lower-level units are automatically removed. The order of field display for date_select( ) can be set using the :order => [ symbols,... ] option, where the symbols are :year, :month, and :day. In addition, all the options from the select_xxx widgets are supported.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值