1

我已經安裝了以下寶石,並試圖實現日期選擇器。日期選擇器出現在字段中,但是當我選擇日期時,數據不會持續存在,甚至不會顯示在該字段中。我是否在使用我的coffeescript或html時犯了錯誤 - 或者這可能是寶石之間的不兼容?bootstrap-datepicker-rails - 選擇日期不會持久

gem 'bootstrap-sass' 
gem 'bootstrap-datepicker-rails' 

http://www.eyecon.ro/bootstrap-datepicker/

https://github.com/Nerian/bootstrap-datepicker-rails

articles.js.coffeescript

jQuery -> 
    $('#datepicker').datepicker() 
    dateFormat: 'yyyy-mm-dd' 
    weekStart: 0 
    autoclose: true 

_form.html.erb

<div class="field" id="datepicker" data-date="current" > 
    <%= f.label :due %> 
    <%= f.text_field :due, 'data-behaviour' => 'datepicker' %> 
</div> 

回答

1

嘗試下載ラw文件從http://www.eyecon.ro/bootstrap-datepicker/並將它們分別放置到您的JavaScript和樣式表目錄中。然後,在你的application.js確保你有

//= require bootstrap-datepicker 

在你application.css文件

*= require datepicker 

在你的視圖文件,首先嚐試的代碼這個簡單的行(你可以把它裏面DIV,但刪除您的DIV的ID):

<%= f.text_field :due, :id => "datepicker" %> 

和(在同一文件的末尾)

<script> 
$('#datepicker').datepicker({format: 'mm-dd-yyyy'}); 
</script> 
+0

這個回答幫助呢? – thewheelz

3

在引導日期選擇器的格式,你需要格式化日期是這樣的:

<script type="text/javascript"> 
$(document).ready(function(){ 
    $('[data-behaviour=datepicker]').datepicker({format: 'yyyy-mm-dd'}); 
}); 
</script>