I am quite newbie to rails and stuck with a problem.

In my application I have a Ajax.updater call to update counties list in
a select drop down whenever a city name is selected. I need to do this
in many place in my application. Currently the Ajax is working fine. But
the get_counties action is in the controller. So I am using this action
in all controllers that I need. However, it would be nice if I could
move this to a County or City model or application_helper.rb . Calling
this method from application_helper is not working as rails/ajax still
looks for this action in the controller. How can I deal with this? And
in general what will be the best place to add this method.

Below is my code:

Controller action:
--------------------------
  def get_counties
   @county = {}
   @counties = {}
   @fake_county_name = '(city)'
    if not params[:id].blank?
      index = params[:id]
      @counties = County.find(:all, :conditions=> ["city_id = ? AND name
!= ?", index, @fake_county_name ], :order=>"name")
    end
    render :partial => 'county', :locals=>{ "counties"=>@counties,
"county"=>@counties }
  end


--------------------------

--------------------------
--------------------------

View partial:
--------------------------
<table>
<tr>
<td class="selectcity">
<label for='city_id'>Select city:* </label></td><td class="cityselect">
<span id="selectcity">
     <select id="city_id" name="user[city_id]" onchange="new
Ajax.Updater('selectcounty', 'get_counties',
                         {asychronous:true, evalScripts:true,
parameters:'id='+value})">
        <option value=""></option>
        <%=
options_from_collection_for_select(@cities,"id","name",@city[:id]) %>
</select>
</span>
</td>
</tr>
<tr>
<td class="selectcounty">
<label for='county_id'>Select county:* </label></td><td
class="countyselect">
<span id="selectcounty">
    <select id="user_county_id" name="user[county_id]">
        <option value=""></option>
        <%= options_from_collection_for_select(@counties, "id", "name",
@county[:id]) %>
    </select>
</span>
</td>
</tr>

</table>

-------------------------

-------------------------
_section.rhtml
<select id="user_section_id" name="user[section_id]">
    <option value=""></option>
    <%= options_from_collection_for_select(@secs, "id", "name",
@sec[:id]) %>
</select>
-------------------------


Cheers,
CS.
-- 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to