Render :partial + redirect_to :controller

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

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

Chris H. wrote:

are you using RJS templates?

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

Thanks!

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