Is it possible in Rails to check whether a redirect or render had already been issued?

前端 未结 1 1727
情歌与酒
情歌与酒 2021-01-03 19:12

Ruby 2.0.2, Rails 4.0.3, Sorcery 0.8.5

I tried to issue a redirect in my code, only to receive the error message that a redirect or render had already been issued.

1条回答
  •  误落风尘
    2021-01-03 20:12

    You can call performed? in your controller to check if render or redirect_to has been called already:

    performed?               # => false
    redirect_to(login_path)
    performed?               # => true 
    

    Read more about performed? in the Rails docs.

    0 讨论(0)
提交回复
热议问题