Hello,
thanks a lot for you help. I am having some issues in understanding how fields_for works. I have a location model that has_many :ads. I would like to do a form for filtering locations and ads. I am thinking of using the following syntax:
<%= form_for(@locations) do |f| %>
<%= f.label :country, "Description" %>
<%= f.text_field :country, :class => "form-control" %>
then I would use the fields_for(@locations, @locations.ads.build) for those fields that are part of the Ad model, but I am not able to make this work because @locations.ads is an array.
<% fields_for(@locations, @locations.ads.build) do |u| %>
<%= u.label :skill_list, "Skills" %>
<%= u.text_field :skill_list %>
<% end %>
So I am trying to understand how should I use fields_for with @locations.ads.build?
Could you please give me any advice, explanation and help?
I am doing this because I want to do @locations = Location.all, the filter the ads based on the @location.country and @ads.skill_list
Thanks a lot
Fabrizio
What I have tried:
I have been searching online for explanation and I thought of posting a question about this