URLを指定して表示
適応バージョン
- 1.0.0
 - 1.1.0
 - 1.1.1
 - 1.1.6
 - 1.2.0
 - 1.2.6
 - 2.0.0
 - 2.0.1
 - 2.0.3
 - 2.1.0
 - 2.2.1
 - 2.3.2
 - 2.3.8
 - 3.0.0
 - 3.0.5
 - 3.0.7
 - 3.0.9
 - 3.1.0
 - 3.2.3
 - 3.2.8
 - 3.2.13
 - 4.0.2
 - 4.1.8
 - 4.2.1
 - 4.2.7
 - 4.2.9
 - 5.0.0.1
 - 5.1.7
 - 5.2.3
 - 6.0.2.1
 - 7.0.0
 
説明
URLを指定して表示
使い方
redirect_to(オプション={}, レスポンスオプション={})
オプション
| オプション | 説明 | 
|---|---|
| :alert | エラーメッセージを表示 | 
| :notice | 通知用のメッセージを表示 | 
| :flash | パラメータを使って、一時的に値を保存 | 
ステータスコード
| シンボル | コード | 説明 | 
|---|---|---|
| :ok | 200 | 成功 | 
| :created | 201 | リソースの生成に成功 | 
| :moved_permanently | 301 | リソースが永続的にリダイレクト | 
| :found | 302 | リソースが一時的にリダイレクト | 
| :see_other | 303 | リソースが別の場所にある | 
| :bad_request | 400 | 不正なリクエスト | 
| :unauthorized | 401 | 未承認 | 
| :forbidden | 403 | アクセス禁止 | 
| :not_found | 404 | リソースが存在しない | 
| :method_not_allowed | 405 | HTMLメソッドが許可されていない | 
| :internal_server_error | 500 | 内部サーバエラー | 
例
指定したページにリダイレクト
redirect_to action: "show", id: 5
インスタンス変数
redirect_to @post
URL
redirect_to "http://www.rubyonrails.org"
ステータスコード指定
redirect_to post_url(@post), status: 301
エラーメッセージを表示
redirect_to post_url(@post), alert: "Watch it, mister!"
通知メッセージを表示
redirect_to post_url(@post), status: :found, notice: "Pay attention to the road"
flash指定
redirect_to post_url(@post), status: 301, flash: { updated_post_id: @post.id }