【问题标题】:DatePicker jquery and simple_form_forDatePicker jquery 和 simple_form_for
【发布时间】:2012-12-06 21:25:56
【问题描述】:

我正在尝试在我的 simple_form 中使用 Jquery 日期选择器。

我有一个字段

<%= simple_form_for @customer, :html => { :class => 'form-horizontal' } do |f| %>
<%= render "shared/error_messages", :target => @customer %>
  <%= f.input :start_lease_date, :as => :text %>
<% end %>

我已经安装了 Jquery-ui gem,我在我的 application.js 中添加了 require 选项

//= require jquery.ui.datepicker

我还在 application.css 中添加了 require

 *= require jquery.ui.datepicker

我还添加了 customer.js.coffee 文件,其中包含以下内容

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

但是,我的 Start_lease_date 字段仍然没有显示日期选择器

【问题讨论】:

  • 可能看起来很明显,但您是否在您的应用程序/js 中包含 //= require jquery
  • 你能用你的 application.js 文件(只是顶部)和 require 等更新你的问题

标签: ruby-on-rails simple-form


【解决方案1】:

我想以下方法会起作用

<%= f.input :start_lease_date, :as => :text, 
            :input_html => { :class => 'date_picker' }  %>

 <%= f.input :start_lease_date, :as => :date_picker %>

【讨论】:

    【解决方案2】:

    我会大胆猜测并说您还没有运行/安装 Jquery。 Jquery-UI 依赖于 Jquery 才能工作

    【讨论】:

      【解决方案3】:

      尝试将此添加到您的 gem 文件中...

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

      ...这个到你的 app/assets/javascripts/application.js

      //= require jquery.ui.datepicker
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-30
        • 2013-01-07
        • 2011-11-15
        • 2010-09-28
        • 2013-02-10
        • 2012-09-20
        相关资源
        最近更新 更多