2017-07-03 6 views
0

それぞれのサブドメインに正常にサインアップした後、ユーザーをリダイレクトしようとしています。私はapplication_controller内に次のコードを入力しました。rails devise after_sign_up_path_for未定義のメソッド `subdomain '

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 

答えて

0

NoMethodErrorを受け付けております:: SessionsController#がゼロのため `サブドメインを未定義のメソッドを作成します:NilClass

@usersnilなので、Railsはそのエラーで吐き出されます。 Deviseを使用しているときは、Deviseモデル(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 
関連する問題