1
votes

We are trying to route a new user to fill out a Fact Sheet on their first login and then land on their Dashboard the rest of the time.

Going on this post here: devise first login with rails

We added this to our application controller:

def 
after_sign_in_path_for(user) 
redirect_to ((current_user.sign_in_count == 0) ? new_fact_sheet_path : dashboard_index_path )
end

But we get this error:

"AbstractController::DoubleRenderError in Devise::RegistrationsController#create Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".

We thought we were overriding Devise default routing with a redirect in the application controller?

Solution: This ended up being a two-part solution as noted in comments below. Code that worked:

def 
after_sign_in_path_for(user) 
((current_user.sign_in_count == 1) ? new_fact_sheet_path : dashboard_index_path )
end
2

2 Answers

3
votes

I think the reason for your DoubleRenderError is because after_sign_in_path_for(resource_or_scope) should just return the path which is later used to redirect by devise. However, you're calling redirect_to within your overridden after_sign_in_path_for(), so it is being redirected twice. Just drop the redirect_to and simply return the appropriate path.

0
votes

I think it should be on DeviseSessionController, read this: Devise After first login redirect

the people used the same thing and it works.