Cameron Bass Cameron Bass - 2 months ago 13
Ruby Question

Devise Session Controller. Custom routing on failure

Right now I'm extending the Devise sessions controller. Everything is working fine except that when the password is typed wrong or it can't find the user. it tries to redirect_to the sessions#new. I do not want that for my case I want it to redirect to a custom route because this is coming from a different view than the sessions new view. I know about

but I'm not sure that is what I want because my particular case is the warden.authenticate! method. In the auth_options there is a recall hash. That is where I want to customize my route. Here is my sessions controller.

Session Controller

class SessionsController < Devise::SessionsController
def create

super do |user|
if params[:user][:invitation_id].present?
invitation = Invitation.find(params[:user][:invitation_id])

if !user.accounts.exists?(id:
user.accounts << invitation.account
flash[:tip_off] = "You now have access to your project \"#{}\""
flash[:tip_off] = "You are already a member of #{}"

cookies[:account_id] =

As I stated before this works fine I just need a custom routes upon failure of password or email. Right now it goes to sessions#new, that does not work for my case. Any help would be great! Thanks


You can override recall value on auth_option method to redirect to another route on failure.

def auth_option
  { scope: resource_name, recall: "#{controller_path}#another_new_path" }