# RJS behave differently than render :partial?

**URL:** <https://www.ruby-forum.com/t/rjs-behave-differently-than-render-partial/94912>\
**Category:** Rails\
**Created:** [May 17, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/rjs-behave-differently-than-render-partial/94912 "2006-05-17T17:13:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [May 17, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/rjs-behave-differently-than-render-partial/94912/1 "2006-05-17T17:13:29Z")

</div>

I have a method in my controller like the following (the syntax may not  
be correct, I’m doing this from memory - you should be able to get the  
idea though) My rhtml page has a DIV with id=“country\_areas”, which  
contains a partial that only makes a drop down of country areas for a  
specific country. When changing the country in the country drop down, it  
uses the :observe\_field to call the below method and refresh the  
country\_areas partial.

def find\_country\_areas  
@country\_areas = Country.find(:all, :condition =\> (“country\_id =?”,  
params[:country\_id]) )  
render :partial =\> “country\_areas”, :object =\> @country\_areas  
end

The country areas drop down is getting changed to reflect those country  
areas that are for a specific country, so all is well.

Now if I change the above method to:

def find\_country\_areas  
@country\_areas = Country.find(:all, :condition =\> (“country\_id =?”,  
params[:country\_id]) )  
end

and use a find\_country\_areas.rjs:

page.relace ‘country\_areas’, :partial =\> ‘country\_areas’, :object =\>  
‘@country\_areas’

it works correctly the first time I change a country. But any subsequent  
changes to the country drop down do not re-render the partial at all (ie  
the same areas are populated as the first country I selected). My method  
is getting called, but no refresh of the partial.

Why do these behave differently? I want to use rjs because ultimately I  
have two partials that I want to refresh.

Thanks  
Brian

---

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [May 17, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/rjs-behave-differently-than-render-partial/94912/2 "2006-05-17T17:47:09Z")

</div>

Hi !

2006/5/17, Brian N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> page.relace ‘country\_areas’, :partial =\> ‘country\_areas’, :object =\>  
> ‘@country\_areas’

Don’t pass a string as the object, but do pass the instance variable.

page.relace ‘country\_areas’, :partial =\> ‘country\_areas’,  
:object =\> @country\_areas

Notice no apostrophes around@contry\_areas. You had an error because  
your partial was receiving a String object when it expected an  
Enumerable.

Bye !

---

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [May 17, 2006, 7:41pm UTC](https://www.ruby-forum.com/t/rjs-behave-differently-than-render-partial/94912/3 "2006-05-17T19:41:28Z")

</div>

Look at the generated code and you should see the difference. I  
imagine it’s the difference between one replacing the innerHTML and  
the other the outerHTML. Note that render :partial is not the same  
things as page.replace.

Michael

---

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [May 17, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/rjs-behave-differently-than-render-partial/94912/4 "2006-05-17T18:35:53Z")

</div>

FranÃ§ois Beausoleil wrote:

> Hi !
> 
> 2006/5/17, Brian N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > page.relace ‘country\_areas’, :partial =\> ‘country\_areas’, :object =\>  
> > ‘@country\_areas’
> 
> Don’t pass a string as the object, but do pass the instance variable.
> 
> page.relace ‘country\_areas’, :partial =\> ‘country\_areas’,  
> :object =\> @country\_areas
> 
> Notice no apostrophes around@contry\_areas. You had an error because  
> your partial was receiving a String object when it expected an  
> Enumerable.
> 
> Bye !

I think that is the way I have it - without quotes (sorry trying to  
remember something that is at home while I am at work). Otherwise, I  
don’t think it would even work the first time. Is there anything else  
that would cause these to work differently?
