When user tries to fill form using script or automation, application controller raises error of the
"ActionController::InvalidAuthenticityToken"
This happens for valid genuine users when they fill a form, close their browser, reopens the page from their browser history and submit form.
In this case I don't want to send an exception using exception notifier, and I also want to show the modal with the refreshed request message.
So I have modified application_controller as
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  rescue_from ActionController::InvalidAuthenticityToken, with: :handle_csrf_error
  def handle_csrf_error(exception)
    respond_to do |format|
      format.js {
        render 'invalid_requests/error'
      }
      format.html {
        render text: I18n.t('errors.messages.csrf_error')
      }
    end
    ExceptionNotifier.notify_exception(exception)
  end
end
I want to make this works for all types of requests.
I have added responses for the html & js requests
But not getting how to handle the json request.
P.S > json request is sent from web application for load more case & sometimes exception raises, so want I to handle this.
My Rails version is 4.2