dmberko11
dmberko11

Reputation: 467

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!

Upvotes: 0

Views: 680

Answers (1)

nourza
nourza

Reputation: 2321

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

Upvotes: 2

Related Questions