Rails アプリには、json 文字列を返すアクションがあります。次のようになります。
if exist_user
format.json { render json: {:msg => 'has this user'}}
else
しかし、レールはエラーを表示します:引数が少なすぎます
カスタム json 文字列をレンダリングするにはどうすればよいですか?
Rails アプリには、json 文字列を返すアクションがあります。次のようになります。
if exist_user
format.json { render json: {:msg => 'has this user'}}
else
しかし、レールはエラーを表示します:引数が少なすぎます
カスタム json 文字列をレンダリングするにはどうすればよいですか?
ブロックする必要がありrespond_to
ます。そうしないと、送り返すフォーマットがわかりません。
respond_to do |format|
if exist_user
format.json { render json: {:msg => 'has this user'} }
else
end
end
詳細については、http://api.rubyonrails.org/classes/ActionController/Responder.htmlを参照してください。
if exist_user
format.json { render :json => {:msg => 'has this user'} }
else