ITeye博客

Rails 3 时间日期相关的表单处理

夜鸣猪 · 2011-07-27 04:30 · RubyOnRails · 编程语言 · Markdown

默认是date_select


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

比较流行呢,用jquery的UI做的datepicker



<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>



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



#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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。