Rails 3: redirect_to with :remote => true

后端 未结 4 860
春和景丽
春和景丽 2020-12-20 19:20

I have a delete link that makes a remote call:

<%= link_to image_tag(\"trash.png\"), [current_user, bookcase], method:  :delete, :remote => true, confi         


        
相关标签:
4条回答
  • 2020-12-20 19:51

    I tried the accepted answer but didn't work for me (RAILS 6), what worked for me is this :

    format.js { redirect_to current_user }
    

    Hope this help someone

    0 讨论(0)
  • 2020-12-20 19:53

    Don't know if this is answering this specific question, but some might find the following helpful:

    module AjaxHelper
      def ajax_redirect_to(redirect_uri)
        { js: "window.location.replace('#{redirect_uri}');" }
      end
    end
    
    class SomeController < ApplicationController
      include AjaxHelper
    
      def some_action
        respond_to do |format|
          format.js { render ajax_redirect_to(some_path) }
        end
      end
    end
    
    0 讨论(0)
  • 2020-12-20 19:53

    I am pretty sure this code will work.

    render :js => "window.location = '/jobs/index'
    

    You can use this code in action /controller_name/action name/

    0 讨论(0)
  • 2020-12-20 20:07

    I'm pretty sure you can specify the format in the redirect_to like this

    redirect_to current_user, format: 'js'

    0 讨论(0)
提交回复
热议问题