简体   繁体   English

Bootstrap Datepicker gem没有在Rails中格式化

[英]Bootstrap Datepicker gem not formatting in rails

I know this type of question has come up before on SO, and I have tried every solution I could find, but nothing seems to work. 我知道这类问题以前曾在SO上出现过,我已经尝试了所有可以找到的解决方案,但似乎没有任何效果。 The javascript is working fine, but for some reason, I can't get the datepicker window to go in the right spot or format correctly. javascript工作正常,但由于某些原因,我无法使datepicker窗口进入正确的位置或正确设置格式。 After testing multiple gems, I keep getting this: 在测试了多个宝石之后,我不断得到这个:

在此处输入图片说明

There are no errors in my console. 我的控制台中没有错误。 Here is what my related gems look like in my Gemfile : 这是我的Gemfile与我相关的宝石的外观:

gem 'jquery-rails', "~> 2.3.0"
gem 'bootstrap-sass'
gem 'bootstrap-datepicker-rails'

And here is my application.js 这是我的application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require bootstrap-datepicker
//= require_self

And my application.css has: 我的application.css有:

*= require bootstrap-datepicker

As for the actual html file, it looks like this ( application#index.html ) 至于实际的html文件,它看起来像这样( application#index.html

<input type="text" data-behaviour='datepicker' >

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

Any and all ideas are welcome. 任何想法都欢迎。

UPDATE: 更新:

It seems like my bootstrap css files aren't loading at all. 看来我的引导CSS文件根本没有加载。 Do I need to use css.scss files? 我需要使用css.scss文件吗? I can't seem to find a straightforward answer online. 我似乎无法在网上找到简单的答案。 Manually inserting the css into my application.css file results in this: 手动将css插入我的application.css文件会导致以下结果:

在此处输入图片说明

Just for a sanity check give the standard jquery datepicker a shot. 只是为了进行健全性检查,请为标准jQuery datepicker试一下。 I generally use it with bootstrap. 我通常将其与引导程序一起使用。

app/assets/javascripts/application.js app / assets / javascripts / application.js

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require jquery.ui.datepicker
//= require jquery.timepicker.js
//= require_tree .

app/assets/stylesheets/application.css 应用程序/资产/样式表/application.css

 *= require jquery.ui.datepicker
 *= require jquery.timepicker.css
 *= require_self
 *= require_tree .

app/assets/javascripts/your_model.js.coffee app / assets / javascripts / your_model.js.coffee

jQuery ->
  $("#div_id_here").datepicker dateFormat: "yy-mm-dd"

Since you're using bootstrap-sass, you can (and should) use @import statements instead of *= require statements for your css.scss files. 由于您使用的是bootstrap-sass,因此您可以(也应该)使用@import语句代替css.scss文件的*= require语句。 This allows you to define and use variables, etc amongst all of your css.scss files, which allows for full customization of Bootstrap and its components. 这样,您就可以在所有css.scss文件中定义和使用变量等,从而可以完全自定义Bootstrap及其组件。 I'm not sure if there could be something else wrong with your configuration... but I'd suggest starting here anyway since none of your css is showing up. 我不确定您的配置是否还有其他问题...但是我还是建议从这里开始,因为您的CSS都没有出现。 So your application.css.scss file would look like: 因此,您的application.css.scss文件如下所示:

# @import any file that may contain variables you'd like to use in any libraries
# added below this point (e.g. `defines.css.css`)
@import "bootstrap_and_overrides";
@import "bootstrap-datepicker";
# @import "whatever other .css.scss files you have...";

Then in bootstrap.css.scss you'd individually import each of the desired bootstrap CSS components after "overriding" any variables. 然后,在bootstrap.css.scss您可以在“覆盖”任何变量之后分别导入每个所需的Bootstrap CSS组件。 Here is what you need to start from: 您需要从这里开始:

  • variables (this is the basis your variable/style "overrides", placed at the tope of your bootstrap_and_overrides.css.scss file.) 变量 (这是变量/样式“替代”的基础,放置在bootstrap_and_overrides.css.scss文件的顶部)。
  • bootstrap components (this is the core of your bootstrap_and_overrides.css.scss file.) 引导程序组件 (这是bootstrap_and_overrides.css.scss文件的核心。)

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

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