I have a rails form that includes a parent, child, and a child of the child. I'm using the nested_form gem and my rails version is 4.1. The issue I'm encountering is with a nested form with a nested field within it. I don't want to have the user add the nested resource with a button, but I want the nested object to be instantiated when the view loads.
Parent Model
class LoanApplication < ActiveRecord::Base
# Associations
has_many :business_contacts, :dependent => :destroy
# Nested Object
accepts_nested_attributes_for :business_contacts, :allow_destroy => true
end
Child of Parent
class BusinessContact < ActiveRecord::Base
# Associations
belongs_to :loan_application
has_one :personal_guarantee
# Nested objects
accepts_nested_attributes_for :personal_guarantee, :allow_destroy => true
end
Child of Child (Grandchild to Parent)
class PersonalGuarantee < ActiveRecord::Base
# Associations
belongs_to :business_contact
end
View
<%= f.fields_for :business_contacts, :wrapper => true do |contact_form| %>
<%= contact_form.fields_for :personal_guarantee do |guarantee| %>
<%= guarantee.text_field :guarantor_net_worth %>
<% end %>
<% end %>
The business_Contacts fields show up fine, but the child of business_contacts aren't showing up. I've nested the personal_guarantee fields in the params hash of loan_application_controller.
loan_application_controller.rb
def loan_applications_params
params.require(:loan_application).permit(:loan_application_id, business_contacts_attributes: [:id, :business_salesforce_id, :prefix, :first_name, :exp_revenue_growth, :last_name, :business_title, :is_employee, :equity_hurdle, :contact_railsid, :guarantor_gender, :guarantor_sin_number, :guarantor_date_of_birth, :guarantor_phone_number, :guarantor_street_address, :guarantor_city, :guarantor_postal_code, :guarantor_province, :_destroy, personal_guarantee_attributes: [:id, :guarantor_net_worth]]
end
As I mentioned above, with the above setup, I can't see to see the PersonalGuarantee field in the form.