Using Ajax to render a partial in rails -
this post last chance work out why ajax call doesn't work in project. hope guys give me hand.
what solely want render partial of "orders" administration page clicking on "link_to" button.
this have in controller called "masters":
class masterscontroller < applicationcontroller before_action :logged_in_master, only: [:index, :edit, :update, :destroy] before_action :correct_master, only: [:edit, :update] def administration @orders = order.all respond_to |format| format.html format.json format.js end end
my view called "administration.html.erb":
<% provide(:title, "administration") %> <h1>manage site</h1> <ul class="nav nav-pills"> <li role="presentation" class="active"><%= link_to "masters", masters_path %></li> <li role="presentation"><%= link_to "orders", orders_path, action:remote => true %></li> <li role="presentation"><%= link_to "settings", edit_master_path(current_master) %></li> <li role="presentation"><%= link_to "services", manage_path %></li> <li style="float:right;" role="presentation"><%= link_to "log out", logout_path, method: "delete" %></li> </ul> <div class="activity"> </div>
my js format of view called "administration.js.erb":
var orders_inject = $("<%= escape_javascript(render (:partial => 'orders')) %>"); $('.activity').html(orders_inject); , partial called "orders": <table class="table table-hover table-striped"> <thead> <tr> <th>name</th> <th>field</th> <th>description</th> <th>address</th> <th>time</th> <th>mobile number</th> <th>photo</th> <th>master</th> </tr> </thead> <tbody> <% @orders.each |order| %> <tr class="active"> <td><%= order.name %></td> <td><%= order.field %></td> <td><%= order.description %></td> <td><%= order.address %></td> <td><%= order.datetime %></td> <td><%= order.mobile_number %></td> <td><%= order.photo %></td> <td><%= order.master_id %></td> <td><%= link_to 'add master', edit_order_path(order), class: 'btn btn-info btn-sm' %></td> <td><%= link_to 'delete order', order, method: :delete, data: { confirm: 'are sure?' }, class: 'btn btn-danger btn-xs' %> </td> </tr> <% end %> </tbody> </table>
so please, me figure out i've been reading various related post week , still no solution bug. appreciate comment , advice. in advance!
$('.activity').html("<%= j raw render 'orders' %>")
where 'orders' located in app/views/masters/orders.html.erb
Comments
Post a Comment