# Rendering partial in iframe results in Bad URI

**URL:** <https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388>\
**Category:** Rails\
**Created:** [February 27, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388 "2008-02-27T22:13:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [February 27, 2008, 10:13pm UTC](https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388/1 "2008-02-27T22:13:50Z")

</div>

Rendering my partial in the src attribute of an iframe results in a bad  
uri message. When I don’t render the partial in the iframe it works  
just fine.  
Why does one work and not the other?

_ **Doesn’t Work** _

_ **Works** _  
\<%= render :partial =\> ‘subscreens’ %\>

This same approach (calling within a iframe) works on a different page  
however it makes the iframe so small you can’t see the contents. This  
however is a different issue. I just didn’t want to make two posts  
related to iframe issues.

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [February 28, 2008, 12:37am UTC](https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388/2 "2008-02-28T00:37:12Z")

</div>

Corey M. wrote:

> Rendering my partial in the src attribute of an iframe results in a bad  
> uri message. When I don’t render the partial in the iframe it works  
> just fine.  
> Why does one work and not the other?
> 
> _ **Doesn’t Work** _

The iframe src attribute is a URL, not the content. So you want:

def subscreens() render :partial =\> ‘subscreens’, :layout =\> false end

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

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [February 28, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388/3 "2008-02-28T17:10:42Z")

</div>

Mark Reginald J. wrote:

> The iframe src attribute is a URL, not the content. So you want:
> 
> def subscreens() render :partial =\> ‘subscreens’, :layout =\> false end
> 
> –  
> We develop, watch us RoR, in numbers too big to ignore.

Thanks. That makes perfect sense, however my instance variables that I  
had coming into the page are now gone. I’ve illustrated how my page  
works without the iframe to clarify my problem.

Step Action

1. Setup instance vars in controller
2. Show main content page
3. Render partial within main page (partial relies on some of the  
instance vars)

Using this approach works just fine since I’m not calling back to a  
method in my controller to render the partial. When using the “iframe”  
approach I’m now calling back to the controller to render the partial  
what’s the best way to retain my instance vars that I previously setup?

Thanks for the help,

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [February 28, 2008, 5:44pm UTC](https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388/4 "2008-02-28T17:44:30Z")

</div>

Corey M. wrote:

> Thanks. That makes perfect sense, however my instance variables that I  
> had coming into the page are now gone. I’ve illustrated how my page  
> works without the iframe to clarify my problem.
> 
> Step Action
> 
> 1. Setup instance vars in controller
> 2. Show main content page
> 3. Render partial within main page (partial relies on some of the  
> instance vars)
> 
> Using this approach works just fine since I’m not calling back to a  
> method in my controller to render the partial. When using the “iframe”  
> approach I’m now calling back to the controller to render the partial  
> what’s the best way to retain my instance vars that I previously setup?
> 
> Thanks for the help,

I fixed my issue by just moving the declarations of my instance vars to  
the new method that renders the partial and all is well. Thanks a bunch  
for the help!

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [February 28, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388/5 "2008-02-28T21:08:52Z")

</div>

Frederick C. wrote:

> Add suitable parameters to the url\_for so that it can retrieve the  
> appropriate content/state.  
> You’ll probably have some common logic shared between the ‘main’ page  
> and the iframe action, so something like a before\_filter may be in  
> order.
> 
> Fred

Cool. Thanks for that advice. I can see filters coming in handy here.  
Now that I’ve got the contents within my iframe rendering properly, how  
do I update that partial? I can’t just call another “render :partial  
…” from my controller since the partial is now inside the iframe. Do  
I need to use javascript to do an innerHTML replacement of my iframe  
contents? Getting the data to display initially is fine but if I can’t  
dynamically refresh it later, using an iframe is pointless.

---

<div class="post-metadata">

**Author:** ![rubylicious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/91b2a8/32.png) [@rubylicious](https://www.ruby-forum.com/u/rubylicious)\
**Post date:** [February 28, 2008, 7:38pm UTC](https://www.ruby-forum.com/t/rendering-partial-in-iframe-results-in-bad-uri/130388/6 "2008-02-28T19:38:04Z")

</div>

On 28 Feb 2008, at 16:10, Corey M. wrote:

> > –
> 
> 1. Show main content page
> 2. Render partial within main page (partial relies on some of the  
> instance vars)
> 
> Using this approach works just fine since I’m not calling back to a  
> method in my controller to render the partial. When using the  
> “iframe”  
> approach I’m now calling back to the controller to render the partial  
> what’s the best way to retain my instance vars that I previously  
> setup?

Add suitable parameters to the url\_for so that it can retrieve the  
appropriate content/state.  
You’ll probably have some common logic shared between the ‘main’ page  
and the iframe action, so something like a before\_filter may be in  
order.

Fred
