Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?

More than 3 years have passed since last update.

@taigamikami

【Rails5】モデルでbefore_actionでfalse返って来てるのに以降の処理やられちゃう問題

throw(:abort)でOK

例えばモデルでerrors配列にエラーの文言を格納し、それをチェックするメソッドをbefore_◯◯◯で設定するとする。

Rails4

その際にRails4では

errors.blank?

的な感じでerrorsの中身があればfalseを返し、これで以降の処理は行わなかった。
しかし、Rails5では異なるようで。。。(泣)

Rails5

Rails5ではコールバックで処理を戻したいときに

throw(:abort) unledd errors.blank?

というふうに throw(:abort)を使う必要があるようです!!

0
Help us understand the problem. What is going on with this article?
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
0
Help us understand the problem. What is going on with this article?