开发者

Devise override redirect after form submit

开发者 https://www.devze.com 2023-02-07 05:12 出处:网络
How can I configure my Rails app such that after the form to create a new user is submitted (thr开发者_运维百科ough devise), I redirect to my own desired page ?

How can I configure my Rails app such that after the form to create a new user is submitted (thr开发者_运维百科ough devise), I redirect to my own desired page ?

Thank you


After the create user form is submitted the user is created and then logged in so the page you are being redirected to is actually the after log in page. If you only want to change this page when a user is created you can set session["#{resource_name}_return_to"] in a custom registration controller like this:

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

You can also create a root route for your user object in routes.rb which will redirect all users whenever they log in:

match "user_root" => "users#home"

Finally you can define the after_sign_in_path_for(resource_or_scope) method in your application_controller and this will allow you to conditionally redirect users:

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

精彩评论

暂无评论...
验证码 换一张
取 消