if you want choose states depending countries, you have to use the ajax
way. That is when rails renders the page, it doesn''t know which
country
you will choose. Thus you have to write javascript code to watch the
country field, when it changes, the code sends messages to server and use
reponse messages to renew the options.
On Monday, October 21, 2013 5:25:53 AM UTC+8, Ruby-Forum.com User
wrote:>
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/5bae2952-8353-43ce-b37a-f4d7a5147848%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.