Think of a redirect when registering with an error

I have a simple Devise registration form with a plugin validatable. It basically works as intended, if the user forgets to enter a name, he redirects them back with a red confirmation.

The problem is that it redirects to the same path in which a successful login should go to the user (i.e. redirects them to /userand does not return to /user/sign_up). If the user then refreshes the page for any reason, they get an error No route matches [GET] "/user".

How can I make the redirection return to the original route /user/sign_upwhen registration fails? I know that I can hack an action createin the registration controller, but when I redirect to the correct route, I lose development check messages.


Update

It seems the problem is how Devise handles respond_with Rails 4 How to overwrite the error response method after the error . It seems like Devise is trying to map the template createto / user, but I still can't override it.

+4
source share
2 answers

First you can create development controllers using the following command -

rails generate devise:controllers users

Then you need to change your routes for development

# 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 this works.

+6
source

sign_up layout. , <html> title .

rails generate devise:controllers users

:

devise :users, controllers: { registrations: "users/registrations" }

Devise, .

class Users::RegistrationController < Devise::RegistrationsController
  layout "new_registration", only: [:new, :create]
end
-1

Source: https://habr.com/ru/post/1694621/


All Articles