How do I write a jQuery function to swap out a partial in Rails 3?
Total newb here so please don't assume that I know anything :)
I'm trying to create a page for teams that will allow you to perform a couple of different tasks. What I would like to do is create a link on the page for each task and then swap out the partial in the center of the page so that the user can perform that task.
So, in my show.html.erb page I have a link like this:
<a href="#" id="add_team_mate">Add a Team Mate</a>
and a div like this:
<div开发者_C百科 id="team_action">
In application.js, I have a function like this:
jQuery(function($){
$("#add_team_mate").click(function() {
alert("Hello world!");
return false;
});
});
which is just a placeholder until I can figure out how to swap out the content in <div id=team_action">
with an appropriate partial. Any help or pointers to jQuery documentation or tutorials would be greatly appreciated.
Thanks!
I'd do something like jQuery("#team_action").empty().append(<new partial html goes here>);
. you'd get the partial from an ajax rendered view? Sorry I'm not versed in ruby and can't help with that.
EDIT: Empty() removes all the contents. Append() will add the partial inside the div.
http://api.jquery.com/empty/
http://api.jquery.com/append/
精彩评论