作用域控制器的after_sign_in_url_for(资源)



我在Users::OmniauthCallbacksController内部,试图调用redirect_to after_sign_in_url_for(@user),但users/被附加到我的控制器上。我该如何阻止这种情况的发生?

一些调试:

>> after_sign_in_path_for(@user)
=> {:controller=>"expert_questions", :action=>"index"}
>> url_for(after_sign_in_path_for(@user))
!! #<ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"users/expert_questions"}>

试试这个:

  def after_sign_in_path_for(user)
    if user.admin
      '/admin'
    else
      '/'
    end
  end

您可以使用url助手重定向到{:controller=>"expert_questions", :action=>"index"}

def after_sign_in_path_for(@user)
  expert_questions_index_path
end

最新更新