rails redirect_to format html sends response in js

后端 未结 3 1367
粉色の甜心
粉色の甜心 2020-12-11 04:32

I made a before_filter in some of my controller to redirect keyword searches to the parent controller

It\'s very simple:

  before_filter :redirect_se         


        
相关标签:
3条回答
  • 2020-12-11 05:03

    I think the problem is in the view which is doing the request

    you are sending a JS request (ajax), so you should return a js.erb file and render new HTML using js

    0 讨论(0)
  • 2020-12-11 05:09

    Try with

    def redirect_search
         respond_to do |format|
                format.html {redirect_to buildings_path} if params[:q].present?
                format.js {render :js => "window.location.href='"+buildings_path+"'"} if params[:q].present?
         end
    end
    
    0 讨论(0)
  • 2020-12-11 05:24

    Thanks to Bachan's answer, I could solve my issue this way:

      def redirect_search
        render :js => "window.location.href='"+buildings_path+"'" if params[:q].present?
      end
    

    Thanks!

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