jquery - Rails - How to re-render partial after Ajax GET method request -
rail4,jquery ajax
i need display order 1 day chosen on - jquery datepicker.
i set ajax request , make staff contoroller can't make works. need advise.
order_controller
def index @order = params[:date] ? order.where(date: params[:date]) : order.get_order_today respond_to |format| format.html # render index.html.haml end
end
order.js.coffee
$ -> $('#datepicker').datepicker dateformat: 'yy-mm-dd', onselect: (datestr) -> $.ajax -> type: "get", url: "orders/index", datatype: "html", data: {date: datestr} success: -> # should here render default index view? console.log("everything ok ;)")
view/orders/index
#order.col-xs-12.col-sm-6.col-md-8 = render 'orders/order' #datepicker.col-xs-6.col-md-4.date-picker-div
view/orders/_order
%h3 order info %table.table.table-striped %tr %th meal %th price - if (!@order.nil?) - @order.products.each |one_order| %tr %th=one_order.product_name %th=one_order.product_price - else %tr %th no order yet %th - if (!@order.nil?) .col-md-8 %span=link_to "cancel order", delete_order_path(id: @order.id), method: :delete, :data => {:confirm => "you sure?"}, class: "btn btn-primary" - else .col-md-8 %span=link_to "create order", new_order_path , class: "btn btn-primary" .col-md-4.total-price-div %h4 order coast: #{get_order_coast}
- console show me when day chosen on datepicker
console:
add in controller index
def index @order = params[:date] ? order.where(date: params[:date]) : order.get_order_today respond_to |format| format.html # render index.html.haml format.js # render js request end end
then response in ajax success or can create index.js.erb response
$("#activity_detail").html('<%= escape_javascript(render :partial => 'orders/order') %>');
Comments
Post a Comment