3 doubts on observe_field

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


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


. . .

==== city_controller.rb

*** QUESTION 3: How I can receive the value from @form_country_id for
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)

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


Eleudson Queiroz
removed_ema[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs