简体   繁体   English

是什么原因导致datepicker没有在带有jquery的rails 3.1.3中加载?

[英]What causes datepicker not loading in rails 3.1.3 with jquery?

We have a very simple use of datepicker in rails 3.1.3 app with jquery. 我们在rails 3.1.3 app中使用jquery非常简单地使用了datepicker。 However there are 2 views on which datepicker does not load. 但是,有两个视图无法加载datepicker。 On all other views, datepicker loads itself without problem. 在所有其他视图上,datepicker加载自己没有问题。 All js code for datepicker is in application.js file and one of them (not loading) looks like this (with head file): datepicker的所有js代码都在application.js文件中,其中一个(不加载)看起来像这样(带头文件):

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

$(function() {
   $("#src_plant_src_since").datepicker({dateFormat: 'yy-mm-dd'});
});

Here is the simple form code in view: 以下是视图中的简单表单代码:

<%= f.input :src_since, :label => 'start date:', :hint => 'start src date', :as => :string %>

What could be the reason causing datepicker loads on one view and not one another? 导致datepicker加载一个视图而不是另一个视图的原因是什么? Thanks so much. 非常感谢。

Gemfile 的Gemfile

group :assets do
    gem 'jquery-ui-rails'
end

application.js 的application.js

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all 
//= require_tree .

Or you can load only the datepicker js. 或者你只能加载datepicker js。 Like: 喜欢:

//= require jquery.ui.datepicker

Try this 尝试这个

install 安装

gem "jquery_datepicker"

then this in ur form 这是你的形式

<%= f.label :date %>
 <%= f.datepicker :date, :dateFormat => 'dd MM, yy',  :showOn => "both", :buttonImage => "../assets/calendar.gif", :buttonImageOnly => true, :changeMonth => true, :changeYear => true, :placeholder => "Click on the textfield/Calender" %><br/>

This u should put inside application.html inside your layouts 你应该在你的布局中放入application.html

<%= 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" %>

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

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