class DeviseController

def require_no_authentication

before_action :require_no_authentication, only: :new
Example:

Helper for use in before_actions where no authentication is required.
def require_no_authentication
  assert_is_devise_resource!
  return unless is_navigational_format?
  no_input = devise_mapping.no_input_strategies
  authenticated = if no_input.present?
    args = no_input.dup.push scope: resource_name
    warden.authenticate?(*args)
  else
    warden.authenticated?(resource_name)
  end
  if authenticated && resource = warden.user(resource_name)
    set_flash_message(:alert, 'already_authenticated', scope: 'devise.failure')
    redirect_to after_sign_in_path_for(resource)
  end
end