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

respond_with について [ 自分用メモ ]

More than 3 years have passed since last update.

参考サイト
http://blog.livedoor.jp/sasata299/archives/51804693.html
http://d.hatena.ne.jp/shilen40/20130515/1368624103

例)
class UsersController < ApplicationController::Base
 respond_to :html, :xml, :json

 def index
  respond_with(@users = User.all)
 end

 def create
  @user = User.create(params[:user])
  respond_with(@user, location: users_url)
 end
end

・respond_toとペアで使って上のように書くことができる。
・respond_withメソッドを使うときは、respond_toメソッドとペアで使う必要がある。
・respond_toメソッドで指定していないフォーマットでアクセスされると、406 Not Acceptableエラーを返す。

dawn_628
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