I have two partials _choose.html.erb and _details.html.erb.
I render choose like so:
<div id="choose" class="box" style="padding:10px;" >
<%= render :partial => "choose" %>
</div>
In the controller I call the choose method.
def choose
respond_to do |format|
format.js
end
end
And in choose.js.erb I call the following:
$("#choose").replaceWith(<%= escape_javascript(render(:partial => "details"))%>);
But nothing happens. The details partial is in the correct place and if I render it in the page, like so <%= render :partial => "details" %>, up it pops no problem. But I am unable to swap it using the above ajax method.
If I do:
$("#choose").replaceWith("a yaddy yaddy");
"a yaddy yaddy" is rendered in the choose div.
Am I missing something here?
I have been reading around, including SO, but to no avail.
Update
The response is either a 200
or a 304
. And using firebug, I can see that the response contains the partial contents but this is not rendered in the browser, which is strange, but I'd imagine I have committed some sneaky grievance I'm unaware of....
Update
in choose.js.erb:
If I call "$("#choose").html("<%= escape_javascript(render(:partial => "choose", :object => @pages))%>开发者_运维技巧")"
the choose partial is updated with the pages instance variable.
Thanks, y'all.
Can you make sure that both of your partials have a id = "choose"
div in them? If not, your replaceWith
is dropping them. Could you possible want .html("")
?
精彩评论