# RJS to refresh partial not working

**URL:** <https://www.ruby-forum.com/t/rjs-to-refresh-partial-not-working/87507>\
**Category:** Rails\
**Created:** [March 3, 2007, 4:57am UTC](https://www.ruby-forum.com/t/rjs-to-refresh-partial-not-working/87507 "2007-03-03T04:57:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ee59a6/32.png) [@wcheung](https://www.ruby-forum.com/u/wcheung)\
**Post date:** [March 3, 2007, 4:57am UTC](https://www.ruby-forum.com/t/rjs-to-refresh-partial-not-working/87507/1 "2007-03-03T04:57:10Z")

</div>

Hi,

I have the following:

\_list\_user.rhtml

* * *
 \<% for column in User.content\_columns %\> \<% end %\> 

\<% for user in @users %\>

 \<% for column in user.content\_columns %\> \<% end %\>

```
<td><%= link_to 'Edit', :action => 'user', :id => user, :user_info

```

=\> @user\_info %\>

\<% end %\>

| \<%= column.human\_name %\> |
| --- |
| \<%=h user.send(column.name) %\> | \<%= link\_to ‘Destroy’, { :action =\> ‘destroy\_user’, :id =\>  
user, :user\_info =\> @user\_info }, :confirm =\> ‘Are you sure?’, :post  
=\> true %\> |

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

user.rhtml

* * *

\<%= render :partial =\> 'list\_user', :user\_info =\> @user\_info %\>

\<% form\_remote\_tag :url =\> { :action =\> ‘update\_user’, :id =\>  
@user, :user\_info =\> @user } do %\>  
\<%= render :partial =\> ‘user\_form’ %\>  
\<%= submit\_tag ‘Save’ %\>  
\<% end %\>

* * *

update\_user.rjs

* * *

page.replace\_html(“list\_user”, :partial =\> ‘list\_user’, :user\_info =\>  
@user\_info )

* * *

For some reason, when I click on “Save”, it doesn’t update the  
\_list\_user.rhtml partial. In fact, it updates the model but the  
partial doesn’t refresh. Is there something wrong with the partial?  
I put page.alert(‘RJS works!’) in my update\_user.rjs and that  
works…

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![wcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ee59a6/32.png) [@wcheung](https://www.ruby-forum.com/u/wcheung)\
**Post date:** [March 3, 2007, 6:28am UTC](https://www.ruby-forum.com/t/rjs-to-refresh-partial-not-working/87507/2 "2007-03-03T06:28:14Z")

</div>

So I looked into this a little more and it seems like the new updated  
data doesn’t get refreshed right after I click “save”. When I refresh  
the page again, that’s when the data is refreshed. I’m not sure how  
the form submits to the server, but apparently the page.replace\_html  
happens BEFORE the data is submitted. Any ideas?

---

<div class="post-metadata">

**Author:** ![wcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ee59a6/32.png) [@wcheung](https://www.ruby-forum.com/u/wcheung)\
**Post date:** [March 3, 2007, 7:31am UTC](https://www.ruby-forum.com/t/rjs-to-refresh-partial-not-working/87507/3 "2007-03-03T07:31:17Z")

</div>

On 3/3/07, wcheung [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have the following:  
> […]  
> For some reason, when I click on “Save”, it doesn’t update the  
> \_list\_user.rhtml partial. In fact, it updates the model but the  
> partial doesn’t refresh. Is there something wrong with the partial?  
> I put page.alert(‘RJS works!’) in my update\_user.rjs and that  
> works…

The explanation I can think of is that you didn’t fetch the @users  
in the update\_user action in your controller. That’s how you see  
the data when you refresh the page (since you must have fetched  
@users in your users action) but not in the RJS update.

d.

---

<div class="post-metadata">

**Author:** ![wcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ee59a6/32.png) [@wcheung](https://www.ruby-forum.com/u/wcheung)\
**Post date:** [March 3, 2007, 8:55pm UTC](https://www.ruby-forum.com/t/rjs-to-refresh-partial-not-working/87507/4 "2007-03-03T20:55:43Z")

</div>

On 3/3/07, wcheung [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hmm…I have @users in update\_user action (it was complaining before in  
> the log). But it’s still not updating the data before the  
> page.replace\_html. Any other ideas? Is there anything I’m doing  
> wrong with the form?

Having re-read your snippets, there is one line that really troubles me:

page.replace\_html(“list\_user”, :partial =\> ‘list\_user’,  
:user\_info=\>@user\_info )

I don’t think this line will work. Your partial is using the @user\_info  
in the  
controller, that the one passed by the line above. So if your action  
doesn’t  
fetch @user\_info, there’s no data for the partial to use.

To pass a “local variable” to the template, pass  
:locals=\>{:user\_info=\>@user\_info}  
in the render parameter, then replace the member variable @user\_info  
with user\_info in the partial. Hope this works.

d.

---

<div class="post-metadata">

**Author:** ![wcheung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ee59a6/32.png) [@wcheung](https://www.ruby-forum.com/u/wcheung)\
**Post date:** [March 3, 2007, 7:59am UTC](https://www.ruby-forum.com/t/rjs-to-refresh-partial-not-working/87507/5 "2007-03-03T07:59:18Z")

</div>

Hmm…I have @users in update\_user action (it was complaining before in  
the log). But it’s still not updating the data before the  
page.replace\_html. Any other ideas? Is there anything I’m doing  
wrong with the form?
