Dear friends, with the yours aid already I obtained to use
observe_field, but still I am with some problems and necessary again.
They are three questions to long of the source code below.
Since already I am grateful for the tips.
==== _form.rhtml
<!--[form:city]-->
<p><label
for="city_state_country_id">Pa?s</label><br/>
<select id="city_state_country_id"
name="city.state[country_id]">
*** QUESTION 1: How I can know if I am in the action new or edit without
needing to create the @is_new variable?
<% if @is_new %>
<option selected value="0">Selecione um Pa?s</option>
<% @form_country_id = 0 %>
<% else%>
<% @form_country_id = @city.state["country_id"] %>
<% end%>
<%= options_from_collection_for_select @countries, "id",
"nome",
@form_country_id %>
</select></p>
<%= observe_field(:city_state_country_id,
:update => :select_state,
:url => {:action => :ajax_states_from_country}
)
%>
*** QUESTION 2: How to force the exhibition of select_state when the
page is loaded and it did not have change of value of country_id?
This operation is necessary to show the state field in the edition
action of the data.
<p><label
for="city_state_id">Estado</label><br/></p>
<div id="select_state"></div>
.
.
.
==== city_controller.rb
*** QUESTION 3: How I can receive the value from @form_country_id for
parameter?
Not to need to use request.raw_post...
def ajax_states_from_country
@states = State.find(:all, :order => "nome", :conditions =>
["country_id = ?", request.raw_post])
render(:layout => false)
end
==== ajax_states_from_country.rhtml
... and not to use @form_country_id variable from _form.rhtml.
<select id="city_state_id" name="city[state_id]">
<%= options_from_collection_for_select @states, "id",
"nome",
@form_country_id %>
</select>
Regards,
Eleudson Queiroz
jinfo@mandic.com.br
--
Posted via http://www.ruby-forum.com/.