LoginSignup
0
0

More than 1 year has passed since last update.

【Rails】ArgumentError (Unrecognized status code :ng):

Posted at

症状

RailsAPIモードでアクションを呼び出したときに、下記エラーが発生しました。
翻訳すると、「ArgumentError(認識されないステータスコード:ng):」

error
ArgumentError (Unrecognized status code :ng):

該当のソースです。

HogeController.rb
  def hoge
    user = User.find_by(id: params[:userId])

    if(true)
      render json: {}, status: :ok
    else
      render json: {}, status: :ng
    end
  end

解決方法

statusコードを普段使用されるステータスコードにすることで解決しました。
コードの一覧はこちらを参考にしました↓

HogeController.rb
  def hoge
    user = User.find_by(id: params[:userId])

    if(true)
      render json: {user: user}, status: :ok
    else
      render json: {}, status: :unauthorized
    end
  end

参考

0
0
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
0
0