I'm using the Reform gem to make a form object in my current project but the nested fields don't show up in the form. Here's my code:
Shipment Model:
class Shipment < ApplicationRecord
has_one :shipment_detail
end
ShipmentDetail Model:
class ShipmentDetail < ApplicationRecord
belongs_to :shipment
end
Reform Class
class ShipmentForm < Reform::Form
property :shipment_type
property :measure
property :shipment_detail do
property :po_number
property :job_no
end
end
Controller
class ShipmentsController < ApplicationController
def new
@shipment = ShipmentForm.new(Shipment.new)
end
end
Template
<%= form_for @shipment, url: shipments_path, method: :post do |f| %>
<%= f.label :shipment_type %><br />
<%= f.text_field :shipment_type %><br /><br />
<%= f.label :measure %><br />
<%= f.text_field :measure %><br /><br />
<%= f.fields_for :shipment_detail do |d| %>
<%= d.label :po_number %><br />
<%= d.text_field :po_number %><br /><br />
<%= d.label :job_no %>
<%= d.text_field :job_no %><br /><br />
<% end %>
<% end %>
Only fields shipment_type
and measure
are visible on the form, po_number
and job_no
are not. What should I do to make them visible?