Problem with multiple insert

I have 2 model:
Company
has_many :company_references

CompanyReference
belongs_to :companies
in create form i have multiple entries for references:

i am doing in view like :

<% for j in 0…2 %>

<%= text_field "cr_person_name",j.to_s,:size=>'10' %> <%= text_field "cr_company_name",j.to_s,:size=>'10' %> <%= text_field "cr_relationship",j.to_s,:size=>'10' %> <%= text_field "cr_contact_no",j.to_s,:size=>'10' %> <%= text_field "cr_emailid",j.to_s,:size=>'10' %> <% end%>

and saving them like :
create action:
@company = Company.new(params[:company])
for j in 0…2
@company.company_references << CompanyReference.new({“contact_no” =>
params[“cr_contact_no”][j.to_s],
“company_name” =>params[“cr_company_name”][j.to_s],
“relationship” =>params[“cr_relationship”][j.to_s],
“emailid” => params[“cr_emailid”][j.to_s],
“person_name” => params[“cr_person_name”][j.to_s],
})
end
@company.save

but i don’t like this method, could anyone suggest best approach

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs