How can i associate item with the association. Here an example and here the models
-Customer
-Phone
-PhoneType
Customer Phone PhoneType
Id Id Id
First Number Description
Last Phone_Type_Id
Email isViewed
Password
...
The relationship his has follow
Customer
has_many phone
accepts_nested_attributes_for :phone, allow_destroy: :true
Phone
belongs_to :customer
has_one :phone_type
accepts_nested_attributes_for :phone, allow_destroy: :true
PhoneType
belongs_to :phone
The way my form view work his has follow in
Customer#edit view
I render a general form which consist of other fields and inside of it I have the following code
<%= f.fields_for :phones do |b| %>
<fieldset>
<%= b.label :number %>
<%= b.select :PhoneType %> ## issues is here
<%= b.label :isViewed %>
</fieldset>
<% end %>
Thanks in advance!
try
instead of using camelcase (PhoneType) in the form. Your association in the phone model expects a field called :phone_type so you need to fix the case.
Also, what is being rendered in your views with the way they are now? Are you getting any errors?
So you want go give the user the option to select a phone type by choose a description from the dropdown? You might try something like
Finally, you might want to take a look at the simple form gem….
https://github.com/plataformatec/simple_form/