I am having a hard time to alter the where condition of the grouped_collection_select collection: Country.where("name='Brazil'") not to use hard coded value, but the form value.
This is how it is working: <%= f.grouped_collection_select(:state, Country.where("name='Brazil'").order(:name), :states, :name, :id, :name) %>
This is what I am trying to do: <%= f.grouped_collection_select(:state, Country.where(:name=>:state).order(:name), :states, :name, :id, :name) %>
<%= form_for(@address, :url => {:action => 'update', :controller => 'addresses', :id => @address.id}) do |f| %> <%= render "shared/error_messages", :target => @address %>
<table id="TbUser" summary="User form fields"> <tr> <th colspan="2" style="background-color: #fff; text-align:left">Dados do Cliente</th> </tr> <tr> <th>Endereço</th> <td><%= f.text_field(:address) %></td> </tr> <tr> <th>Bairro</th> <td><%= f.text_field(:neighborhood) %></td> </tr> <tr> <th>Cidade</th> <td><%= f.text_field(:city) %></td> </tr> <tr> <th>Estado</th>
<td><%= f.grouped_collection_select(:state, Country.where("name='Brazil'").order(:name), :states, :name, :id, :name) %></td> </tr> <tr> <th>Cep</th> <td><%= f.text_field(:zipcode) %></td> </tr> <tr> <th>País</th> <td><%= f.text_field(:country) %></td> </tr> <tr> <th colspan="2" style="background-color:white; text-align: center"><%= submit_tag("Atualizar") %></th> </tr> </table> <div>
</div> <% end %>