I've been struggling with an error appearing while rendering multiple partials to one specific page. A have 4 different buttons in my administration panel and I want each of them to call an ajax call to render 4 different partials accordingly. Unfortunately, when I'm trying to make it happen, it happens to work on one button only, the rest doesn't respond at all.
Here's my action in controller:
def administration
@orders = Order.all
respond_to do |format|
format.json
format.html
format.js
end
end
My view:
<% provide(:title, "Administration") %>
<h1>Manage your site</h1>
<section>
<div class="tabs tabs-style-bar">
<nav>
<ul>
<li><%= link_to "Masters", {:controller => 'masters', :action => 'index'}, class: "link fa fa-group", :remote => true %>
</li>
<li><%= link_to "Orders", {:controller => 'masters', :action => 'administration'}, class: "fa fa-tasks", :remote => true %>
</li>
<li><%= link_to "Services", {:controller => 'masters', :action => 'services'}, class: "fa fa-tags", :remote => true %>
</li>
<li><%= link_to "Settings", edit_master_path(current_master), class: "fa fa-cogs" %>
</li>
</ul>
</nav>
</div><!-- /tabs -->
</section>
<div class="orders"></div>
<div class="masters"></div>
<div class="services"></div>
and My JS receiver:
var orders_inject = $("<%= j raw render 'orders' %>");
$('.orders').html(orders_inject);
So please, let me work it all out as it's been quite long since the error occurred!
Hope this will work for you, try this and change your render files. I just suppose here partial test1
and test2
$(".orders").replaceWith("<%= j(render('test1') %>");
$(".services").replaceWith("<%= j(render('test2') %>");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.