rails link_to :remote

前端 未结 2 1818
旧巷少年郎
旧巷少年郎 2020-12-23 02:32

I have the following:

<%= link_to my_path, method: :delete, confirm: \'Delete?\', class: \'link-delete\', \'data-message\' => \'Are you sure?\', \'data         


        
相关标签:
2条回答
  • 2020-12-23 02:58

    You can bind to ajax calls like this:

    <%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %>
      <i class="icon-trash"></i>
    <% end %>
    
    $('.link-delete').bind('ajax:beforeSend', function() {
      $('#mySpinner').show();
    });
    
    $('.link-delete').bind('ajax:complete', function() {
      $('#mySpinner').hide();
    });
    
    0 讨论(0)
  • 2020-12-23 03:17

    You don't need to combine the two. Just use the format.js to call the javascript.

    In your controller:

    Controller

     def my_method
         #code here
         respond_to do |format|
          format.js  {}
         end
        end
    

    my_method.html.erb

    <div id = "link-delete"></div>
    

    my_method.js.erb

    $("#link-delete").html("<%= escape_javascript(render(:partial => "text_message"))%>");
    

    _text_message.html.erb

    <p>Loading...</p>
    
    0 讨论(0)
提交回复
热议问题