Help us understand the problem. What is going on with this article?

rails で redirect_to 済かどうかを取得する

More than 3 years have passed since last update.

以下のように判定します。

controller.rb
# redirect_to 済であれば、終了する。
return if response_body

※ Rails 3.2 の AbstractController::DoubleRenderError ではこのように判定していました。

なぜこんな判定が必要になったかというと、とあるコードにてAbstractController::DoubleRenderError が発生しました。原因は Controller の public method から別の public method を読んでおり、両方の method で redirect_to が設定されてしまうことでした。

public method が public method を呼んでいる時点で相当に行儀の悪いコードと考えますが、最少工数でこれを発生しなくするために、 redirect_to 済であるか判定して、エラーの発生を抑えています。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away