0

我在成功注册到他们各自的子域后尝试重定向用户。我在 application_controller 中输入了以下代码。

application_controller.rb

protected

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

我收到以下错误

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 
4

1 回答 1

0

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

@usersnil,所以 Rails 吐出这个错误。当您使用 Devise 时,可以使用 访问Devise model( User) 实例resource

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

你也可以使用current_user

def after_sign_in_path_for(resource)
  redirect_to root_url(subdomain: current_user.subdomain)
end
于 2017-07-04T02:30:54.887 回答