Ruby on rails 如何在ruby on rails上正确使用引导数据采集器
在我的Ruby on rails 如何在ruby on rails上正确使用引导数据采集器,ruby-on-rails,ruby,twitter-bootstrap,bootstrap-datepicker,Ruby On Rails,Ruby,Twitter Bootstrap,Bootstrap Datepicker,在我的application.js中,我添加了: //= require jquery3 //= require jquery_ujs //= require bootstrap //= require bootstrap-datepicker 然后我在我的app/helpers/application\u helper.rb中添加了这个助手: def datepicker (form, field) form.text_field(field, data: {provide: "da
application.js
中,我添加了:
//= require jquery3
//= require jquery_ujs
//= require bootstrap
//= require bootstrap-datepicker
然后我在我的app/helpers/application\u helper.rb
中添加了这个助手:
def datepicker (form, field)
form.text_field(field, data: {provide: "datepicker",
'date-format': 'dd/mm/yyyy',
'date-autoclose': 'true',
'date-today-btn': 'linked',
'date-today-highlight': 'true'}).html_safe
end
这是我的表格:
<%= form_with(model: test, local: true) do |form| %>
<% if test.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(myform.errors.count, "error") %> prohibited this test from being saved:</h2>
<ul>
<% test.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :test_name %>
<%= form.text_field :test_name %>
</div>
<div class="field">
<%= form.label :test_desc %>
<%= form.text_field :test_desc %>
</div>
<div class="field">
<%= form.label :test_expan %>
<%= form.text_field :test_expan %>
</div>
<div class="field">
<%= form.label :test_date %>
<%= datepicker(form, :test_date) %>
</div>
<div class="field">
<%= form.label :ci %>
<%= form.text_field :ci %>
</div>
<div class="field">
<%= form.label :test_complete %>
<%= form.check_box :test_complete %>
</div>
<div class="field">
<%= form.label :tester %>
<%= form.text_field :tester %>
</div>
<div class="field">
<%= form.label :test_other_cons %>
<%= form.text_field :test_other_cons %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
禁止保存此测试:
我有一个巨大的表单,其中包含许多文本字段和复选框,但是日期选择器显示在表单的末尾,而不是文本字段的正下方。我的意思是,我希望日历显示在文本字段的正下方,而不是在提交按钮之后
我应该如何着手解决这个问题?我是不是遗漏了什么
另外,我使用的是Linux Mint 18.3、Ruby on Rails 5.2.1,我在Chromiun 69.0.3497.81和Firefox 62.0上进行了测试,两者都相同。这看起来更像是CSS问题,而不是Rails问题。
您应该确保您已经包含了
bootstrap
和bootstrap datepicker
所需的所有CSS文件,这应该可以解决这个问题。检查项目中的样式表/application.css
文件,查看当前包含的css文件。我在我的application.css
文件中添加了*=require bootstrap datepicker
。我需要添加其他东西吗?假设您也有“核心”引导css,并且在自定义css中没有做任何奇怪的事情,可以吗?你也许可以试着去掉页面上除了日期选择器之外的所有东西来缩小问题的范围……你可以安全地假设,当你使用bootstrap的布局网格和移除杂乱的东西(基本上除了日期选择器和表单之外的所有东西)时会发生什么?我在该视图中使用的唯一一个来自bootstrap的东西是日期选择器