0
0

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 3 years have passed since last update.

redirect_toとrenderの違い

Last updated at Posted at 2020-01-27

初投稿です!
説明が足らないと思いますが、見てください!

#redirect_toとrenderの違い

Untitled Diagram.jpg

redirect_toはroutingとcontrollerを通ってviewを表示していますが、renderはいきなりviewを表示させています。
redirect_toでは新たなリクエストがされたのと同じ動きになりますので、controllerを経由してviewが表示されます。
これによって、元のインスタンス変数が上書きされるかどうかが違います。

4行目:redirect_to
6行目:render


def create
  @group = Group.new (params)
  if @group.save
    redirect_to root_path, notice: "グループが作成されました!"
  else
    render :new
  end
end
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?