---
title: "Rails 3 时间日期相关的表单处理"
author: "夜鸣猪"
date: "2011-07-27T04:30:52Z"
tags: []
categories: ["编程语言"]
slug: "rails-3"
draft: false
lastmod: "2011-07-27T04:32:05Z"
id: 1133562
url: "https://hlee.iteye.com/blog/1133562"
---

默认是date_select


```ruby

date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true,
                                  :discard_day => true, :include_blank => true)

```


比较流行呢，用jquery的UI做的datepicker

![](http://dl.iteye.com/upload/attachment/525277/824d48f7-e33b-328e-9b83-21d1586b9a0a.png)


```html


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %>
<%= csrf_meta_tag %>
 <title>Inventory</title>
</head>


```




```ruby

#修改f.date_select as f.text_field
<div>
 <%= f.label :purchased_on %><br />
 <%= f.text_field :purchased_on %>
 </div>


```



```ruby

#public/javascripts/application.js
$(function (){
 $('#product_purchased_on').datepicker();
 });


```



官方的手册如下：
<http://jqueryui.com/demos/datepicker/>
<http://docs.jquery.com/UI/Datepicker/parseDate>

当然asciicast有一个介绍也相当不错
<http://asciicasts.com/episodes/213-calendars>