Forum: Ruby on Rails partials and rjs

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E458de7b2e71b722b7204d001e222b68?d=identicon&s=25 Brian (Guest)
on 2006-06-09 14:10
I must have a misunderstanding of partials, maybe one of you can help me
out. I have a page that initially displayed via the following:

<-- in controller -->
def find_areas_for_country
    @country_areas = CountryArea.find(:all, :conditions => ["country_id
= :country", params], :order => "descr asc")
    render :partial => 'country_area'

<-- my partial -->
<%= select :country_area, :id, @country_areas.collect {|c| [c.descr,]}, {:prompt => "-- Select Area --"},
  {:name => "country_area_select", :onfiltered=> "new
   {asynchronous:true, evalScripts:true});" }

<-- form containing partial -->
   <span id="country_area">
    <%= render :partial => 'country_area' %>
     <span id="add_country_area" style="cursor:pointer;">New</span>
          <%= in_place_editor 'add_country_area',
       :url => {:action => 'add_country_area'},
       :with =>


This creates a drop down list of areas within a country. Now I have an
in_place_editor field (see above), that once you type in a new value and
press submit, calls the following method in the controller:

  def add_country_area
    @country_area = => params[:value],
:country_id => params[:country])
    @country_areas = CountryArea.find(:all, :conditions => ["country_id
= :country", params], :order => "descr asc")

I then have the following rjs defined:
< add_country_area.rjs >
page.replace 'country_area', :partial => 'country_area', :object =>


According to the docs, it looks like page.replace "Replaces the "outer
HTML" (i.e., the entire element, not just its contents) of the DOM
element with the given id"

What happens when this runs, is the origianl drop down adds the value to
drop down that was typed in - say we typed in "test", but then another
drop down along with some _javascript code is added. So it doesn't look
like it is replacing, but rather adding to it. This is what it looks
like - now I have two drop downs!

|drop down|  Element.update("country_area", |2nd drop down|

Could someone help me shed some light on what is going on and help me
figure out what I need to do to get this working such that I end up with
one drop down with whatever I typed in added to the drop down list?

Thanks a lot!
This topic is locked and can not be replied to.