0

I am attempting to redirect user after successfully signing up to their respective subdomain. I have input the following code within the application_controller.

application_controller.rb

protected

def after_sign_in_path_for(resource)
  redirect_to root_url(subdomain: @users.subdomain)
end 

I am receiving the following error

NoMethodError in Devise::SessionsController#create
undefined method `subdomain' for nil:NilClass

Extracted source (around line #10):


def after_sign_up_path_for(subdomain)
  redirect_to root_url(subdomain: @users.subdomain)
end 
nomad
  • 45
  • 9

1 Answers1

0

NoMethodError in Devise::SessionsController#create undefined method `subdomain' for nil:NilClass

@users is nil, so Rails spits out with that error. As you are using Devise, the Devise model(User) instance can be accessed with resource.

def after_sign_in_path_for(resource)
  redirect_to root_url(subdomain: resource.subdomain)
end

You can also use current_user

def after_sign_in_path_for(resource)
  redirect_to root_url(subdomain: current_user.subdomain)
end
Pavan
  • 33,316
  • 7
  • 50
  • 76