0
I need to filter the result of neighborhoods based on the selection of a city. I have a has_many relation through active record. It is possible to perform this filter without Submit?
In the models:
class Cidade < ApplicationRecord
has_many :bairros
end
class Bairro < ApplicationRecord
belongs_to :cidade
end
In view:
<div class="form-group">
<%= f.label :bairro, "Bairro:", class: "col-sm-2 control-label" %>
<div class="col-sm-6">
<%= f.collection_select :bairro_id, @bairros, :id, :nome, {} , class: "form-control" %>
</div>
</div>
<div class="form-group">
<%= f.label :cidade_id, "Cidade:",class: "col-sm-2 control-label" %>
<div class="col-sm-6">
<%= f.collection_select :cidade_id, @cidades, :id, :nome, {} , class: "form-control" %>
</div>
</div>
Hi, Cleber, I really appreciate your help. I managed to create the grouped Collection, however, it always lists all the neighborhoods, indifferent to the selected city. Know some way to bring only the neighborhoods filtered by the city already selected?
– SuBzer0