我试图通过bootstrap-datepicker-rails gem使用simple_form来获取日期选择器(使用bootstrap modal),但没有运气。
我读了很多东西,比如:
https://github.com/Nerian/bootstrap-datepicker-rails/issues/51 How to setup bootstrap-datepicker-rails? http://learningnewtricks.wordpress.com/2013/07/03/bootstrap-date-picker-on-rails-so-simple/ http://www.chadcf.com/blog/jqueryui-datepicker-rails-and-simpleform-easy-way
我得到的只是一个文本字段但是当我点击它时没有日期选择器。可能是日期选择器背后的模态,如果是这样如何解决?
我的设置如下:
fyousuf$ rails -v
Rails 3.2.12
fyousuf$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]
应用/资产/样式表/ application.css
*= require_self
*= require fullcalendar
*= require bootstrap-datepicker
*= require_tree .
应用/资产/ Javascript角/ application.js中
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require bootstrap
//= require fullcalendar
//= require bootstrap-datepicker
//= require_tree .
app / assets / javascript / s / events.js
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$('[data-behaviour~=datepicker]').datepicker({"format": "yyyy-mm-dd", "weekStart": 1, "autoclose": true});
应用/视图/活动/ _form.html.erb
<%= simple_form_for(@event) do |f| %>
...
<%= f.input :starts_at, :as => :string, :input_html => { data: {behaviour: "datepicker"}} %>
...
<% end %>
答案 0 :(得分:3)
= f.input :first_name
= f.input :last_name
= f.input :date_of_birth, as: :string, input_html: { class: "datepicker" }
$(function() {
$('input.datepicker').data({behaviour: "datepicker"}).datepicker();
});
> bundle | grep bootstrap
Using bootstrap-datepicker-rails 1.3.0.2
Using twitter-bootstrap-rails 2.2.8
它非常适合我。加载表单后,如果我点击输入&#34; date_of_birth&#34;日期选择器出现。