I learn Ajax from some time, which is great by the way, so i'm not really an expert of it. So I need some advice about it.
I'm currently building a group system. I have a tab system to differentiate your own groups and the others. What I trying to do know, is script an ajax to send my partial group from a tab to the other. For example when the user quit a group, it will disappear of my groups to appear in the tab others.
I succeed the first step but I don't really know how I can send the form into the other tab. As you can see bellow, I've try to send the id, but there is no partial form include. So it's just rendering the id of my group. Any advices to include the partial (_group2.html.erb) ?
My code :
Index(group):
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane fade in active" id="tab1default_group" style="padding:0px;">
<div class="group_area">
<% @my_groups.each do |group| %>
<div class="group_box<%=group.id%>">
<%= render 'group', group: group %>
</div>
<% end %>
</div>
</div>
<div class="tab-pane fade in" id="tab2default_group" style="padding:0px;">
<div class="group_area2">
<% @groups_out.each do |group| %>
<div class="group_box2<%=group.id%>">
<%= render 'group2', group: group %>
</div>
<% end %>
</div>
</div>
</div>
</div>
rem_req.js.erb(group):
$(".group_box<%=@group.id%>").fadeOut();
$(".group_area2").append('<%= render partial: @group2 %>');
Groups_controller :
def rem_req
if @group.groupes_admin.count == 1 && @group.groupes_admin.where(user_id: current_user).any?
flash[:error] = "Vous devez définir un nouvel Admin ou supprimer ce groupe"
else
RemReqGroupJob.perform_later(current_user, @group)
flash[:error] = "Vous ne faites plus parti de #{@group.name}"
@group2 = Group.where(id: @group.id).last
end
respond_to do |format|
format.html { redirect_back }
format.js
end
end
And when i try to run this, I have this error :
ActionView::Template::Error ('nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.):