2020年12月21日星期一

How to change redirect_to in devise with custom controller?

I use devise with custom controller (user controller). Rather than logging in and going to user/edit, I prefer to serve the home page. To do so, I need to edit the devise session create controller method.

I know I can edit the devise custom controller by following the instructions devise provides:

  # before_action :configure_sign_in_params, only: [:create]      # GET /resource/sign_in    # def new    #   super    # end      # POST /resource/sign_in    # def create    #   super    # end      # DELETE /resource/sign_out    # def destroy    #   super    # end      # protected      # If you have extra params to permit, append them to the sanitizer.    # def configure_sign_in_params    #   devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])    # end    

So following those instructions, how do I simply have the create method do exactly what it currently does, but redirect_to "/" rather than what it's currently doing?

Note here's what it's currently doing:

self.resource = resource_class.new(sign_in_params)  clean_up_passwords(resource)  yield resource if block_given?  respond_with(resource, serialize_options(resource))  

Also note, I could copy that code directly from devise on github, then edit it, like so:

self.resource = resource_class.new(sign_in_params)  clean_up_passwords(resource)  yield resource if block_given?  redirect to: "/"  

but I want to do this using the super method as that's what's recommended in the devise instructions.

https://stackoverflow.com/questions/65401993/how-to-change-redirect-to-in-devise-with-custom-controller December 22, 2020 at 09:03AM

没有评论:

发表评论