Forum: Ruby on Rails render :partial + redirect_to :controller

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.
6dfd01c549aa33a158730c7d9f7064cc?d=identicon&s=25 Da Plutes (plutes)
on 2006-04-03 23:58
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
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-04-04 01:12
(Received via mailing list)
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 => ...
6dfd01c549aa33a158730c7d9f7064cc?d=identicon&s=25 Da Plutes (plutes)
on 2006-04-04 02:19
Chris Hall wrote:
> are you using RJS templates?

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

Aa4cb81d5f9428ddea2329602fdb875e?d=identicon&s=25 Mark Silva (Guest)
on 2006-04-04 18:59
(Received via mailing list)
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 %>

This topic is locked and can not be replied to.