rendering partial in iframe results in Bad URI

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***
<iframe src="<%= render :partial => 'subscreens' %>" scrollbars="auto"
name="subscreens" width=90%></iframe>

***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,

Corey Murphy 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***
<iframe src="<%= render :partial => 'subscreens' %>" scrollbars="auto"
name="subscreens" width=90%></iframe>

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

<iframe src="<%= url_for :action => :subscreens %>" scrollbars="auto"
name="subscreens" width=90%></iframe>

def subscreens() render :partial => 'subscreens', :layout => false end

Mark Reginald James wrote:

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

<iframe src="<%= url_for :action => :subscreens %>" scrollbars="auto"
name="subscreens" width=90%></iframe>

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,

Corey Murphy 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!

Mark Reginald James wrote:

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

<iframe src="<%= url_for :action => :subscreens %>" scrollbars="auto"
name="subscreens" width=90%></iframe>

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?

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

Frederick Cheung 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.