来自Scoped控制器的after_sign_in_url_for(资源)

时间:2016-04-04 21:55:47

标签: ruby-on-rails devise

我在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"}>

2 个答案:

答案 0 :(得分:0)

试试这个:

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

答案 1 :(得分:0)

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

def after_sign_in_path_for(@user)
  expert_questions_index_path
end