3 doubts on observe_field


#1

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

País

*** 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 %>
Selecione um País
<% @form_country_id = 0 %>
<% else%>
<% @form_country_id = @city.state[“country_id”] %>
<% end%>
<%= options_from_collection_for_select @countries, “id”, “nome”,
@form_country_id %>

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

Estado

. . .

==== 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.

<%= options_from_collection_for_select @states, "id", "nome", @form_country_id %>

Regards,

Eleudson Queiroz
removed_email_address@domain.invalid