I need to filter the result of neighborhoods based on the selection of a city. I have a has_many relation through the active record. Is it possible to perform this filter without submitting?
In 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>