Ruby on rails 将引导日期选择器rails添加到表单中的日期选择
因此,我有一个使用“日期选择”的表单,它为每个使用的日期选择(年、月和日)呈现三个选择框 相反,我想使用datepicker,我已经按照说明进行了操作。但是,我不知道如何在视图的表单中实际实现datepicker 我在application.js中使用以下行Ruby on rails 将引导日期选择器rails添加到表单中的日期选择,ruby-on-rails,ruby-on-rails-3,forms,twitter-bootstrap,datepicker,Ruby On Rails,Ruby On Rails 3,Forms,Twitter Bootstrap,Datepicker,因此,我有一个使用“日期选择”的表单,它为每个使用的日期选择(年、月和日)呈现三个选择框 相反,我想使用datepicker,我已经按照说明进行了操作。但是,我不知道如何在视图的表单中实际实现datepicker 我在application.js中使用以下行 $('.datepicker').datepicker() …所以我想我需要给选择框类datepicker <%= form_for @project do |f| %> <div class="text_fie
$('.datepicker').datepicker()
…所以我想我需要给选择框类datepicker
<%= form_for @project do |f| %>
<div class="text_field">
<%= f.label :title%>
<%= f.text_field :title%>
</div>
<div class="text_field">
<%= f.label :description%>
<%= f.text_field :description%>
</div>
<div class="dropdown">
<%= f.label :start_date%>
<%= date_select :start_date, :startdate %>
</div>
<div class="dropdown">
<%= f.label :end_date%>
<%= date_select :end_date, :enddate%>
</div>
<div class="select">
<%= f.label :title%>
</div>
<div class="submit">
<%= f.submit "Spara" %>
</div>
<% end %>
试试:
<%= date_select :start_date, :startdate , :class => 'datepicker' %>
正如gem的安装指南中所述,您应该确保在应用程序.css
和应用程序.js
中都需要它。还有一件更重要的事情:在projects.js.coffee
中,确保加载DOM,如下所示:
jQuery ->
$('.datepicker').datepicker()
谢谢你的回答。现在试过了,但什么也没发生。更奇怪的是,当我检查源代码时,该类甚至没有添加到选择框中:/确保所有require
命令都在那里,并用$(function(){…})包装日期选择器调用代码>日期字段仍然为空?日期字段仍然为空?
jQuery ->
$('.datepicker').datepicker()