我正在尝试在 Rails 4 中制作一个应用程序。
我正在使用简单的表单作为表单,并且刚刚尝试使用 gem 'dependent-fields-rails' 来隐藏或显示基于主要问题的表单字段的子集问题。
我被卡住了。
我已将 gem 添加到我的 gem 文件中:
gem 'dependent-fields-rails'
gem 'underscore-rails'
我已将 application.js 更新为:
//= require dependent-fields
//= require underscore
我有一个表格,其中包含:
<%= f.simple_fields_for :project_date do |pdf| %>
<%= pdf.error_notification %>
<div class="form-inputs">
<%= pdf.input :student_project, as: :radio_buttons, :label => "Is this a project in which students may participate?", autofocus: true %>
<div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="true">
<%= pdf.input :course_project, as: :radio_buttons, :label => "Is this a project students complete for credit towards course assessment?" %>
<%= pdf.input :recurring_project, as: :radio_buttons, :label => "Is this project offered on a recurring basis?" %>
<%= pdf.input :frequency, :label => "How often is this project repeated?", :collection => ["No current plans to repeat this project", "Each semester", "Each year"] %>
</div>
<div class='row'>
<div class="col-md-4">
<%= pdf.input :start_date, :as => :date_picker, :label => "When do you want to get started?" %>
</div>
<div class="col-md-4">
<%= pdf.input :completion_date, :as => :date_picker, :label => "When do you expect to finish?" %>
</div>
<div class="col-md-4">
<%= pdf.input :eoi, :as => :date_picker, :label => 'When are expressions of interest due?' %>
</div>
</div>
</div>
<% end %>
<script type="text/javascript">
$('.datetimepicker').datetimepicker();
</script>
<script>
$(document).ready(function() {
DependentFields.bind()
});
</script>
我对javascript了解不多。
我不确定最后的脚本段落是否必要,或者 gem 是否将其放入代码中。我不确定它是否应该在脚本标签内表达,我也不知道如何使其生效此要求(在依赖字段的 gem 页面上列出):
"Be sure to include underscorejs and jquery in your page."
如何在页面中包含 underscorejs 和 jQuery?我的 gem 文件中有它们。这足够了吗?还是还需要其他东西才能完成这项工作?
目前,当我尝试这种形式时,没有任何内容被隐藏。我尝试将真实值交换为“是”,但这也没有任何区别。
<div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="true">
<div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="yes">
谁能看到我哪里出了问题?