Rails引导Datepicker不工作 [英] Rails bootstrap Datepicker not working
问题描述
我正在尝试对rails应用程序执行datepicker,所以我已经能够使用这两个链接来运行它:
I am trying to implement datepicker to a rails app , so i have been able to run it in reference with these two links :
http://jakoblaegdsmand.com/blog/2012/05/rails-datetime-picker/
https://github.com/Nerian/bootstrap-datepicker-rails
由于某种原因,当我使用脚手架运行时,它运行得很好,但是当我尝试通过构建模型,控制器,视图分别不运行,当我点击日期文本字段时基本没有任何反应。
For some reason it runs just fine when i run it with a scaffold but when i try to run it by building a rails application from scratch by building a model,controller,view respectively its not running,basically nothing happens when i click on the date text field.
这是我写的以下代码。
在宝石文件中
gem 'bootstrap-datepicker-rails'
在appplication.css中
IN the appplication.css
*= require bootstrap-datepicker
在application.js中
In the application.js
//= require bootstrap-datepicker
在_form.html.erb
In the _form.html.erb
<%= form_for(@category) do |f| %>
<%= f.label :Name %><br/>
<%= f.text_field :name %><br/>
<%= f.label :Description %><br/>
<%= f.text_area :description %><br/>
<%= f.label :EmailID %><br/>
<%= f.text_field :emailid %><br/>
<%= f.label :Date %><br/>
<%= f.text_field :cdate, :class => 'datepicker', 'placeholder'=> "dd-mm-yyyy" %><br/>
<script>
$(function() {
$('.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
<% end %>
在Schema.rb中
In Schema.rb
ActiveRecord::Schema.define(version: 20150312163128) do
create_tablecategories,force::cascade做| t |
t.stringname
t.stringemailid
t.textdescription
t.datecdate
t.datetimecreated_at ,null:false
t.datetimeupdated_at,null:false
end
create_table "categories", force: :cascade do |t| t.string "name" t.string "emailid" t.text "description" t.date "cdate" t.datetime "created_at", null: false t.datetime "updated_at", null: false end
end
end
请告诉我做错了什么,自3天以来一直被困在这个。
So kindly tell what i am doing wrong , have been stuck at this since 3 days.
推荐答案
我检查过您的 gihub链接。你的顺序是错误的。 Jquery和jquery-ui应该始终按顺序排列。
I checked your gihub link. And your sequence is wrong. Jquery and jquery-ui should always be first in sequence.
//= require bootstrap-datepicker
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
尝试更新如下:
//= require jquery
//= require jquery_ujs
//= require bootstrap-datepicker
//= require turbolinks
//= require_tree .
这篇关于Rails引导Datepicker不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!