简体   繁体   中英

Devise custom redirects after signup or new session

So I have an rss feed with blog posts you can vote on, but first you have to sign up or sign in to vote and I'm using devise to handle this. I went to this page enter link description here

to understand how to chagne their default redirect to request.reffer, the current page the user was on before having to sign in or sign up, but it's still redirecting back to the root even after I added this to my application controller:

class ApplicationController < ActionController::Base
  protected
    def after_sign_in_path_for(resource)
      request.env['omniauth.origin'] || stored_location_for(resource) || root_path
    end
end

I'm new to rails and web development so if someone could idiot-proof it to me, that'd be much appreciate. Thanks!

You can go even farther by setting stored_locations_for(resource) to nil, and then have different redirects for each action, ie: after_sign_in_path(resource), after_sign_in_path(resource) and so on.

routes.rb

 devise_for :users, controllers: {sessions: 'users/sessions'}

registrations_controller.rb

 class SessionsController < Devise::SessionsController

    protected

      def after_sign_up_path_for(resource)
        example_path
      end
    end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM