Stephane Paquet
Stephane Paquet

Reputation: 2344

protect_from_forgery how to handle resulting exception

When using protect_from_forgery with: :exception in a Web App, how it is possible not to expose the exception to the user.

Let's say that when this exception is raised I would like to refresh the current page and push a flash message on top of the screen (I already have mechanisms to handle the flash messages).

Upvotes: 1

Views: 333

Answers (1)

Avdept
Avdept

Reputation: 2289

You can  add following method

def handle_unverified_request
    render status: 422, template: 'errors/unacceptable'
  end

in your application_controller, and do your error handling there

Upvotes: 1

Related Questions