Building Rails Nested Form Within Nested Form -


i have rails form includes parent, child, , child of child. i'm using nested_form gem , rails version 4.1. issue i'm encountering nested form nested field within it. don't want have user add nested resource button, want nested object instantiated when 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 parent)

class personalguarantee < activerecord::base   # associations   belongs_to :business_contact end 

view

<%= f.fields_for :business_contacts, :wrapper => true |contact_form| %>     <%= contact_form.fields_for :personal_guarantee |guarantee| %>         <%= guarantee.text_field :guarantor_net_worth %>     <% end %> <% end %> 

the business_contacts fields show fine, child of business_contacts aren't showing up. i've nested personal_guarantee fields in 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 mentioned above, above setup, can't see see personalguarantee field in form.

according rails guides fields_for expects options hash third param, second object or nil. please try this:

<%= f.fields_for :business_contacts, nil, :wrapper => true |contact_form| %> 

also, think, objects @ form built.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -