引导程序datepicker日历不会出现在Rails 3中

时间:2015-05-01 07:04:30

标签: ruby datepicker ruby-on-rails-3.2

我在我的Rails应用程序中包含了bootstrap datepicker。但它没有显示任何内容。请检查我的以下代码。

  

的Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.19'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
gem "bcrypt-ruby", :require => "bcrypt"
# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'
gem 'bootstrap-datepicker-rails', '>= 0.6.21'
#gem 'bootstrap-datepicker-rails'
gem 'will_paginate', '~> 3.0'
  

view_report.html.erb:

<div class="input-group bmargindiv1 date" id='datepicker' data-date-format="yyyy-mm-dd" data-date="2015-05-01" data-behaviour='datepicker' >
         <%= form_tag reports_view_report_path, :method => 'get' do %>  
         <%= text_field_tag :search, params[:search], :class => "form-control", :onchange => 'this.form.submit();'%>
           <% end %>
            <span class="input-group-addon">
                <span class="fa fa-calendar"></span>
            </span>
            <script type="text/javascript">
             $(function() {
                $('#datepicker').datepicker()
            });

            </script>
          </div>
  

application.html.erb:

<!DOCTYPE html>
<html>
<head>
  <title>SwargadwaraPuri</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
 <link rel="stylesheet" href="/assets/bootstrap-2.0.css">
<link rel="stylesheet" href="/assets/plugins-2.0.css">
<link rel="stylesheet" href="/assets/main-2.0.css">
<link rel="stylesheet" href="/assets/themes-2.0.css">
</head>
<body class="login no-animation" >

<%= yield %>
<script src="/assets/bootstrap.min-2.0.js"></script>
<script type="text/javascript" src="/assets/bootstrap-filestyle.min.js"></script>
<script src="/assets/plugins-2.0.js"></script>
<script src="/assets/main-2.0.js"></script>
</body>
</html>
  

的application.js

//= require jquery
//= require jquery_ujs
//= require bootstrap-datepicker
//= require_tree .
//= require_self
  

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 .
 *=bootstrap-datepicker
 */

我需要yyyy-mm-dd这样的日期格式。请帮我解决这个问题。我使用的是Rails版本3.2.9。

1 个答案:

答案 0 :(得分:0)

将以下文件添加到application-default.js文件

//= require bootstrap-datepicker
//= require bootstrap-datepicker/core
//= require bootstrap-datepicker/locales/bootstrap-datepicker.es.js
//= require bootstrap-datepicker/locales/bootstrap-datepicker.fr.js

将以下文件添加到application-default.css.scss

*= require bootstrap-datepicker

更改您的javascript,

$('#datepicker').datepicker({
   format: "yyyy-mm-dd"
});

要查看如何更改日期格式,请查看这些bootstrap datepicker并点击该页面上的在线演示链接。