Sunday, October 20, 2013

[Rails] grouped_collection_select collection filter

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 %>

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c598222266e978b81b53d6e083f7495e%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate