0

我用Rails 3.2版本和Ruby 1.9.3日期選擇器不顯示正確的字段

我想要一個的form_tag一個datepicker領域內作出。 在我的GemFile中,我添加了gem'jquery-rails',gem'jquery-ui-rails'和gem'jquery_datepicker'。 在軌控制檯我用命令:軌產生的jQuery:安裝--ui

的application.js看起來是這樣的:

// This is a manifest file that'll be compiled into application.js, which will include all the files 
    // listed below. 
    // 
    // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 
    // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 
    // 
    // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
    // the compiled file. 
    // 
    // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 
    // GO AFTER THE REQUIRES BELOW. 
    // 
    //= require jquery 
    //= require jquery_ujs 
    //= require jquery_ui.all 
    //= require_tree . 

$(function() { 
    $(".datepicker").datepicker({dateFormat: "yy/mm/dd"}); 
}); 

Application.css:

/* 
    * This is a manifest file that'll be compiled into application.css, which will include all the files 
    * listed below. 
    * 
    * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 
    * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 
    * 
    * You're free to add application-wide styles to this file and they'll appear at the top of the 
    * compiled file, but it's generally better to create a new file per style scope. 
    * 
    *= require_self 
    *= require_tree . 
    *= require_jquery.ui.all 
    */ 

And in the view: 

<%= form_tag url: {action: 'do_something'} do |f| %> 
     <%= text_field_tag :birth_date, '', :class => "datepicker" %> 
     <%= submit_tag "Do something man!"%> 
     <% end %> 

有什麼爲form_tag正確調用datepicker函數?

UPDATE1:在Chromium瀏覽器,調試$( 「日期選擇器」)返回null .. 編輯我的文件(感謝Sagar.Patil)

FinalUpdate:我還沒有找到有關這個問題的解決方案。嘗試併成功地使用bootstrap-datepicker。

+0

你可以參考這個[http://apidock.com/rails /v3.2.13/ActionView/Helpers/DateHelper/date_select] –

+0

一件小事:我認爲最好的做法是將require_tree。語句(帶點的語句)保留在所有require語句的底部。 – zwippie

回答

0

製作這改變 的application.js

//= require jquery.ui.all 
$(function() { 
    $(".datepicker").datepicker({dateFormat: "yy/mm/dd"}); 
}); 

application.cs

*= require jquery.ui.all 

查看文件

<%= text_field_tag :birth_date,'', :class => "datepicker" %> 
+0

它輸出裏面有一個文本字段:{:class =>「。datepicker」} – user2786536

+0

結帳我編輯了我的答案。我沒有認識到,這是一個text_field_tag我認爲這是一個text_field –

+0

越來越接近..不只是輸出一個空的文本字段..如果我點擊裏面,沒有任何反應。 – user2786536