How to respond to HTML requests made via AJAX in Rails

后端 未结 4 379
一生所求
一生所求 2021-02-03 15:12

I\'m trying to write a Rails controller method that will respond to get requests made both \"normally\" (e.g. following a link) and via ajax.

Normal Case: The controller

4条回答
  •  失恋的感觉
    2021-02-03 15:51

    In your controller method, simply do this:

       respond_to do |format|
          format.js if request.xhr?
          format.html { redirect_to :action => "index"}
        end
    

提交回复
热议问题