嵌套表格似乎总是会破坏我的大脑。任何帮助,将不胜感激。
我想为课程预订表格。该课程有与之相关的开课日期。我希望表单在从表单中的下拉选项中选择课程后更新课程开始日期。我做了这么多。我已经添加了cocoon gem并且已经设置了所有表单但是我似乎无法获得表单来生成基于表单中选择的课程的列表。
模特:
class Booking < ApplicationRecord
belongs_to :course
belongs_to :user
end
class Course < ApplicationRecord
has_many :bookings
has_many :schedules
accepts_nested_attributes_for :schedules, :reject_if => :all_blank, :allow_destroy => true
end
class Schedule < ApplicationRecord
belongs_to :course
end
表单视图
预订表格
<%= simple_form_for(@booking) do |f| %>
<%= f.error_notification %>
<div class="ice-card">
<!-- <div class="form-inputs">-->
<%= f.input :user_id, :input_html => { :value => current_user.id} %>
<%= f.input :user_email, :input_html => { :value => current_user.email}, label: "Contact Email" %>
<%= f.association :course, label_method: :header, :input_html => { :selected => :course }, :include_blank => false, label: "Course Name" %>
<%= f.simple_fields_for :schedules do |schedule| %>
<%= render 'schedule_fields', :f => schedule %>
<% end %>
</div>
<div class="form-actions">
<%= f.button :submit, class: "btn btn-primary" %>
</div>
<% end %>
安排表格部分
<%= f.input :start_date, as: :date %>