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.rb
and:
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
Devise Login with User or Admin Models and Basecamp Style Subdomains
Regex, How to Match Multiple Lines
Override Ruby Constant in Subclass So Inherited Methods Use New Constant Instead of the Old
How to Customize the Table Builder Plugin for a Week Calendar
How to Push to Faye Server from Rails Controller
Rails 3.2 'Link_To' (In Email) with 'Method: :Put' Still Producing Get Request
How to Make 'Whenever' Gem Work on Windows
What's the Best Way to Unit Test Protected & Private Methods in Ruby
How to Generate Links with Trailing Slash in Rails 3
Force Browser to Download File Instead of Opening It
How to Check If a Ruby Array Includes One of Several Values
Check If an Array Is Subset of Another Array in Ruby
Jekyll Serve Dependency Error - Could Not Open 'Lib Curl'
What Does "||=" Do in Ruby 1.9.2
Rspec --Init Not Working/ 'Mkd Ir': Invalid Argument - ./C: (Errno::Einval)