3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails renderとredirect_toの違い

Posted at

rubyrails.png

  1. 〜とは?
  2. 使用用途
  3. 使い方

render

1.レタリングするテンプレートを指定する。
2.エラーメッセージ表示のために、元の画面に差し戻す際などに利用する。
3. render オプション

redirect_to

1.指定されたページにリダイレクト
2.クライアントにリダイレクト先URLを返却し、クライアントは再度そのURLにリクエストを上げることになる
3.redirect_to(リダイレクト先のURL [, :status => ステイタスコード, オプション])

違い?

・renderがviewファイル(RHTML)を出力して表示するだけ(変数などの値はそのまま)
  ・画面遷移+表示

・redirect_toは再度ページにアクセスする(処理が新たに始まる)
  ・画面遷移+表示+処理の委譲を実行

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?