简体   繁体   English

使用jQuery UI在Rails中输出日期

[英]Date Output in Rails using jquery ui

I have a form where you click in start_date and a jquery calendar comes up to pick the date. 我有一个表单,您在其中单击start_date,然后出现一个jquery日历来选择日期。 I want to display the date as (ex.) September 25, 2012, but I also need rails to comprehend the correct start date not just output it correctly. 我想将日期显示为(例如)2012年9月25日,但是我还需要Rails来理解正确的开始日期,而不仅仅是正确地输出它。

What do i need to add to this? 我需要添加什么呢?

<%= feed_item.start_date %>

events.js.coffee events.js.coffee

jQuery ->
    $('#event_start_date').datepicker
        dateFormat: 'yy-mm-dd'
    $('#event_end_date').datepicker
        dateFormat: 'yy-mm-dd'

Take a look at the altField and the altFormat options for the datepicker. 看一下datepicker的altFieldaltFormat选项。

You can store the Rails-friendly date in a hidden field and pass it to the controller, and display the user-friendly field to the user. 您可以将Rails友好的日期存储在一个隐藏字段中,并将其传递给控制器​​,并向用户显示用户友好的字段。

EDIT 编辑

Take a look at this answer for an example on how to work with altField and altFormat. 请看此答案 ,以获取有关如何使用altField和altFormat的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM