redirect_to没有进入救援区

时间:2016-12-05 19:12:12

标签: ruby-on-rails octokit

我正在使用Octokit登录。

helper_method :user

def show
end 

def user
  client = Octokit::Client.new(access_token: session[:access_token])
  begin
    @user = client.user
  rescue => e
    redirect_to root_path
    return
  end
end 

root_path位于配置

  root to: 'home#new'

执行救援,但是redirect_to没有工作,它返回到与main方法相同的视图。注意:我在很多帖子中都读到过将返回修复它,但它并没有

1 个答案:

答案 0 :(得分:1)

您的代码正在调用redirect_to方法,但救援块随后返回lib.h。相反,将重定向和返回组合成一个语句:

nil

实际上你根本不需要返回,除非在方法中的这个语句之后有什么东西。这是因为在Ruby中隐式返回了最后一个语句。