Matt Wheeler
Matt Wheeler

Reputation: 197

Edit Devise failed registration path - Rails

I've been searching high and low for docs on how to edit the registration path after a failed registration.

I have my signup form on my site index page. On failed registration it redirects to the new_user_registration_path not root where the user was. How do I update this?

Upvotes: 4

Views: 1810

Answers (2)

Jimmy
Jimmy

Reputation: 428

I've been able to achieve this for the sign-up form by using the customfailure app

class CustomFailure < Devise::FailureApp
  def redirect_url
    if warden_options[:scope] == :user
      new_user_registration_path
    else
      new_user_registration_path
    end
  end
  def respond
    if http_auth?
      http_auth
    else
      redirect
    end
  end

  def redirect
    store_location!
    flash[:alert] = i18n_message unless flash[:notice]
    redirect_to '/'
  end
end

Surely a similar option is possible, that doesn't require overriding the devise registrations controller?

Upvotes: 1

sabar
sabar

Reputation: 508

You can copy the devise registrations controller from here

You should be able to add something like this:

if resource.save
    #handle this 
else 
    #handle this
    redirect_to new_user_registration_path
end

Then in your routes:

  devise_for :users, :controllers => {:registrations => 'registrations'}

I'm not sure how to do this without overriding the controller

Upvotes: 0

Related Questions