LoginSignup
6
4

More than 5 years have passed since last update.

padrinoで処理を中断し出力する(phpで言うところのexit)

Last updated at Posted at 2013-09-25

例えばログインエラーなどの共通処理をする際にエラーページへのリダイレクトだと都合が悪い場合、処理を中断して出力したいということがある

exitだとinternal server error、abortだと標準エラーになってしまうのが、以下のようにすると任意の出力をすることができる

            if access_token.nil?
                throw :halt, [200, '{"status":false,"error_code":"109","description":"invalid access_token"}']
            end
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4