Aldo Witzke
Aldo Witzke

Reputation: 41

'Render and/or redirect were called multiple times in this action' on devise

I am using devise and trying to redirect my user after sign up form to a specific template.

I've checked the docs about after_inactive_sign_up_path_for method but I am receiving an exception saying I am redirecting twice.

RegistrationsController < Devise::RegistrationsController

def create
    super
    UsersCreateJob.perform_later(resource.id) if resource.persisted?
end

protected

def after_inactive_sign_up_path_for(resource)
   render template: 'devise/registrations/success'
end
Exception

AbstractController::DoubleRenderError in RegistrationsController#create

Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".

As far as I understand, the after_inactive_sign_up_path_for method overwrites the one from Devise Registration Controller and redirect to my template, right? Where this other template is coming from?

Upvotes: 1

Views: 353

Answers (1)

mrzasa
mrzasa

Reputation: 23327

after_inactive_sign_up_path_for is not meant to render a view. It's a path that will be used for redirect. You should just put a path to an action rendering'devise/registrations/success'.

The error you see is cause by the fact that the devise controller calls render/redirect and then you try to call it as well.

Upvotes: 2

Related Questions