Reputation: 157
I'm using iframe to display some static html files hosted in the same domain in my rails app. I'm adding a link with remote attribute to an element inside the iframe, hoping to make a in-place ajax call to create a new nested resource, like this:
----project.js----
var f = $( ".myFrame" );
f.load(function(){
$(this).find('.jd-details-title').append('<a data-remote="true" href="/projects/10/issues/new" id="new_link">New Issue</a>');
});
----javadocs.html.erb----
<iframe width="100%"
height="1200"
frameborder="0"
scrolling="auto"
class='myFrame'
src= <%= /path/to/static/htmls/ %> >
</iframe>
When I click on this link inside the iframe, the iframe is redirected to the new issue html page, but when it's moved outside the iframe, it magically calls the js version of new issue.
What am I'm missing here? How do I modify this code to get identical behaviors?
Upvotes: 1
Views: 231
Reputation: 3574
The remote: true
is controlled by a javascript library called jquery_ujs
on Rails (you would be able to see that in application.js). Because your iframe page does not include this library, it will not be able to understand the remote: true
(remember that the page inside iframe is completely isolated with the parent page).
In this case, I think you have to handle your link in iframe manually. For example:
$("link_id_inside_iframe").click(function(e){
e.preventDefault();
var link = $(this).attr("href");
$.getScript(link);
});
Upvotes: 1