"неопределенный метод` update 'для nil: NilClass "
Это означает, что @tenant
не имеет escrow
в _escrow_update_form.html.erb
сборкеa escrow
, если @tenant.escrow
равно nil
<% escrow = @tenant.escrow ? @tenant.escrow : @tenant.build_escrow %>
<%= form_for @tenant, url: tenants_escrow_path, method: :patch, validate: true do |a| %>
<%= a.fields_for :escrow, escrow do |f| %>
<%= f.label :new_amount_to_escrow %>
<%= f.number_field(:escrow_payment) %>
<% end %>
<%= a.submit("Done! Go back to the Dashboard", {class: "btn btn-success btn-lg", :id=> 'goalButton'}) %>
<% end %>
В параметрах со вложенными параметрами в белом списке с сильными параметрами
def update
@tenant = current_tenant
if @tenant.update(escrow_params) #updating @tenant will automatically update the corresponding escrow
redirect_to tenants_dashboard_path, notice: "Your escrow payment informaton has been updated"
else
redirect_to tenants_escrow_path, notice: "Your escrow payment was not updated, try again"
end
end
private
def escrow_params
params.require(:tenant).permit(:escrow_payment, :home_value, :total_saved, escrow_attributes: [])
end
end