Devise: Redirect on Sign Up Failure

Devise: redirect on sign up failure?

You will probably need to subclass Devise::RegistrationsController and override the create action. Just copy over the create method from here and modify the redirect on failure to save.

# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController


def create
# modify logic to redirect to root url
end


end

Change your routes to tell Devise to use your controller:

# config/routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}

Why does Devise redirect sign_up error to a different page?

I strongly recommend that you don't do this. The default behavior of Rails applications (following the route naming conventions) is that way you described. But, if you really need to to this, here's how.

First, go to your routes.rband:

devise_scope :user do
post 'users/sign_up', to: 'devise/registrations#create'
end

EDIT

Then, generate the devise views so you can override the default behavior of the forms.

rails g devise:views

Then, open your app/views/devise/registrations/new.html file and edit the form_for line so it looks like this:

<%= form_for(resource, as: resource_name, url: users_sign_up_path) do |f| %>

Devise redirect back on sign up failure with validations

First you can create devise controllers using following command -

rails generate devise:controllers users

Then you have to modify your routes for devise

# config/routes.rb
Rails.application.routes.draw do

devise_for :users,
:skip => [:registrations]

devise_scope :user do
get "user/sign_up", to: "users/registrations#new", as: :new_user_registration
post "user/sign_up", to: "users/registrations#create", as: :user_registration
end

end

Hope it's work.

Devise redirect after users fail signin

I have my auth failure over-ride class in /lib directly.

Here's a bare-bones version that shows how to handle different scopes for users.

class MyAuthFailure < Devise::FailureApp

# add different cases here for diff scopes.
def redirect_url
if warden_options[:scope] == :user
root_path
elsif warden_options[:scope] == :admin
admin_root_path
end
end

# You need to override respond to eliminate recall
def respond
if http_auth?
http_auth
else
redirect
end
end
end

You'd put this class in /lib/my_auth_failure.rb



Related Topics



Leave a reply



Submit