В настоящее время я использую партиал с двойным вложением для добавления дочерних записей в глубоко вложенную форму. Отображаются входные данные формы, но кнопка link_to_add_association вызывает исключение. Как я могу получить доступ к вводу дочерней формы с помощью моей кнопки link_to_add_association?
provider_controller.rb
class ProviderContractsController < ApplicationController
before_action :set_provider_contract, only: %i[show edit update destroy]
def new
@provider_contract = ProviderForm.find(params[:provider_form_id])
@provider_contract = ProviderContract.new(provider_form_id: @provider.id)
@provider_contract.build_contract_term
@provider_contract.contract_term.contract_term_fees.build
rescue ActiveRecord::RecordNotFound
redirect_to home_path, notice: 'The provider has been removed or has not been selected'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_provider_contract
@provider_contract = ProviderContract.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def provider_contract_params
params.require(:provider_contract).permit(ProviderContract.attribute_names.map(&:to_sym),
contract_term_attributes: ContractTerm.attribute_names.map(&:to_sym).push( contract_term_fees_attributes: ContractTermFee.attribute_names.map(&:to_sym).push(:id, :_destroy))
end
end
_form.html.erb
<%= simple_form_for(@provider_contract, html: { class: "ui form"}) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<div class="ui tab" data-tab="stage-4">
<%= f.simple_fields_for :contract_term do |ct| %>
<%= render 'provider_contracts/partials/contract_term', f: ct %>
<% end %>
</div>
<% end %>
_contract_term.html.erb
<div id="#term_fees">
<%= f.simple_fields_for contract_term_fees do |ff| %>
<%= render 'provider_contracts/contract_term_fee_fields', f: ff %>
<% end %>
</div>
<div class="pt-2 pb-2 links">
<%= link_to_add_association f, :contract_term_fees, class: 'ui positive basic button' do %>
Add Fees
<% end %>
</div>
contract_term.rb
class ContractTerm < ApplicationRecord
belongs_to :provider_contract
has_many :contract_term_fees, dependent: :destroy
accepts_nested_attributes_for :contract_term_fees, reject_if: :all_blank, allow_destroy: true
end
Журналы сервера
ActionView::Template::Error (undefined method `reflect_on_association' for NilClass:Class):
62: <% end %>
63: </div>
64: <div class="pt-2 links">
65: <%= link_to_add_association f, :contract_term_fees, class: 'ui secondary basic button' do %>
66: Add Fees
67: <% end %>
68: </div>