LoginSignup
1
2

More than 5 years have passed since last update.

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

Posted at

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

1
2
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
1
2