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


参考サイト
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エラーを返す。