How do I get jQuery to re-render a partial from Ruby and then place it in a div? -
i have button looks this:
<%= link_to "join", "#", :id => "joinleave", :class => "buttonrefresh small join button expand", :'project-id' => @project.id %>
i have jquery called when gets clicked. changes text in button , button function , that, need re-render partial ruby <div>
.
<div class="content" id="peoplerender" data-section-content> <%= render 'people' %> </div>
the .js in "assets/javascript" , view in "apps/views/projects". partials in same folder , work fine when page loads. need update when button pressed.
using jquery, have ajax return update $(".content")
:
your controller
def show @people = whatever_people_logic_you_already_have respond_to |format| format.html format.json render :json => @people.to_json, :layout => false end end end
your ajax :
$.ajax({ url: your_url_to_your_show, type: 'get', success: function(data) { console.log(data); $(".content").html(data); } });
i'm assuming controllers sending proper information. use console.log
identify is.
Comments
Post a Comment