Cancel redirection override after form submission

How do I configure the Rails application so that after the form for creating a new user has been submitted (through the application), I will be redirected to my own page?

thank

+3
source share
1 answer

After creating the user form, the user is created and registered, so the page you are redirected to is actually the page after logging in. If you want to change this page only when creating a user, you can set the session["#{resource_name}_return_to"]registration controller in the user controller as follows:

class Users::RegistrationsController < Devise::RegistrationsController
  def create
    session["#{resource_name}_return_to"] = some_custom_path
    super
  end
end 

route.rb, :

match "user_root" => "users#home"

, after_sign_in_path_for(resource_or_scope) _, :

def after_sign_in_path_for(resource_or_scope)
  if resource_or_scope.is_a?(User)
    some_custom_path    
  else
    super
  end
end
+7

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


All Articles