How to update an iframe element with form_remote_tag?

I have a view with an iframe in it that contains a list of messages. I
would like to update this list from a form in my view that I’ve created
with form_remote_tag.

My code is structured like this right now:
#iframe_view.rhtml#

#index.rhtml#

<% form_remote_tag :update=>“message_list” :url=>“post_message” %>
<%= submit_tag “Post” %>

The problem is that when I submit the form it doesn’t update the
message_list div. I assume that’s because it’s in a separate document.
What should I put in :update so that it will update the message_list
div?

I found a solution–maybe not the best one. For anyone that runs into
the same problem what I did was I created a hidden

and set that as
the :update parameter, then used :complete to call a javascript function
that would copy the returned message into the iframe from the hidden
.

Why can’t you give the iframe an id and just use rjs to insert the
content from the controller?

Corey M. wrote:

I have a iframe that renders a partial (containing a list) using a
“url_for” in the src attribute of the iframe. The list provides the
user the ability to move list items up or down in the list, which I’d
then like to update by re-rendering the partial. Problem is all my
“link_to_remote…” links in the list don’t function now that the partial
is rendered in the iframe. I’m guessing that’s because the
link_to_remotes are attempting to update a div that wraps the iframe but
I wouldn’t know what else to update. Why doesn’t just updating or
re-rendering the partial update the partial within the iframe?

You’ll have to create a special layout for the iframe that wraps
a simple HTML head and body, with the head containing a link
to prototype.js.

May I ask why you’re using an iframe? Could you get away with
an “overflow: auto” div?


We develop, watch us RoR, in numbers too big to ignore.

William P. wrote:

Why can’t you give the iframe an id and just use rjs to insert the
content from the controller?

This is the same dilema I have and I like what this solution poses
however, I’m still not great an using javascript within rails. I’m good
with javascript just not intermixing.

I have a iframe that renders a partial (containing a list) using a
“url_for” in the src attribute of the iframe. The list provides the
user the ability to move list items up or down in the list, which I’d
then like to update by re-rendering the partial. Problem is all my
“link_to_remote…” links in the list don’t function now that the partial
is rendered in the iframe. I’m guessing that’s because the
link_to_remotes are attempting to update a div that wraps the iframe but
I wouldn’t know what else to update. Why doesn’t just updating or
re-rendering the partial update the partial within the iframe?

Mark Reginald J. wrote:

You’ll have to create a special layout for the iframe that wraps
a simple HTML head and body, with the head containing a link
to prototype.js.

May I ask why you’re using an iframe? Could you get away with
an “overflow: auto” div?


We develop, watch us RoR, in numbers too big to ignore.

I ended up using exactly that solution (div with overflow). I was only
looking for the scrolling ability however, once I had encountered the
iframe issue, it became my mission to resolve the problem that way or at
least get a better understanding of why it behaved the way it did.

Thanks for the help,