render partial on click

前端 未结 3 1016
醉梦人生
醉梦人生 2020-12-24 04:15

I would like to call partials on some standard operations. I am using this method for calling the partial:

 %li= link_to \'Delete Event\', \'javascript:void(         


        
3条回答
  •  我在风中等你
    2020-12-24 04:36

    You can do that with javascript like:

    <%= link_to "Delete", delete_content_path, :remote => true %>
    

    The action in your corresponding controller then will be this:

    My Controller:

    def delete_content
      respond_to do |format|               
        format.js
      end        
    end 
    

    Then you can create the delete_content.js.erb inside your correct directory of the link and there you put the following code:

    delete_content.js.erb

    $('#div_id').html("<%= render :partial => 'my_partial' %>");
    

    Then in your view:

    delete_content.html.erb

    #this div is html div that will render your partial

    Don't forget to put your partial _my_partial.html.erb in the same folder.

提交回复
热议问题