# Render :partial + redirect\_to :controller

**URL:** <https://www.ruby-forum.com/t/render-partial-redirect-to-controller/93493>\
**Category:** Rails\
**Created:** [April 3, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/render-partial-redirect-to-controller/93493 "2006-04-03T23:58:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [April 3, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/render-partial-redirect-to-controller/93493/1 "2006-04-03T23:58:04Z")

</div>

This is of course disallowed, which I discovered only after nearly  
completing my spanking new ajaxified UI. What is the motivation behind  
this, and what is the best workaround?

This UI does a scriptaculous drag-and-drop of items from a first div  
(div1) over to a second div (div2), which triggers the contents of div2  
to be updated to reflect the drop. No prob, thus far. But then the  
contents of div1 must be re-sorted via controller (action1) based on  
what has been dropped into div2. THe re-sort of div1 must be done  
server-side. I currently update div2 via render :partial on the tail-end  
of the action (action2) that is triggered by the drop, and then re-sort  
div1 via a submit (form\_remote\_tag) to trigger action1 which does the  
sort and refreshes div1.

It would be nice to be able to either update both div1 and div2 from one  
of the actions, or allow action2 to update div2 via render :partial and  
then redirect\_to action1, but that is not allowed, so what is the best  
recourse to having to use a submit?

Thanks - plutes

---

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [April 4, 2006, 1:12am UTC](https://www.ruby-forum.com/t/render-partial-redirect-to-controller/93493/2 "2006-04-04T01:12:29Z")

</div>

are you using RJS templates?

using RJS you can update as much as you want on a page.

# action to call when element dropped into div2

def drag\_item

# do your work here

render :update do |page|  
page.replace\_html “div2”, :partial =\> …  
page.replace\_html “div1”, :partial =\> …  
end  
end

---

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [April 4, 2006, 2:19am UTC](https://www.ruby-forum.com/t/render-partial-redirect-to-controller/93493/3 "2006-04-04T02:19:33Z")

</div>

Chris H. wrote:

> are you using RJS templates?

No, just heard about them - and it seems like they’ll do the trick.

Thanks!

---

<div class="post-metadata">

**Author:** ![plutes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@plutes](https://www.ruby-forum.com/u/plutes)\
**Post date:** [April 4, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/render-partial-redirect-to-controller/93493/4 "2006-04-04T18:59:04Z")

</div>

Is there a simple way to check for the existence of a partial before  
displaying it?

I have some code that creates a dynamic partial depending on the city a  
particular object is located in. There are some cities that do NOT have  
partials defined for them, but I still want the overall page to  
display. Is there a way to either chefck for existence before  
displaying (enclosed in an if statement?) or to tell the partial to  
skip if it cannot find the file?

\<%= render :partial =\> ‘listing/partials/additional\_’ + @city %\>

Thanks,  
Mark
