I was doing a rails course for progate, and I was wondering about the difference between render and redirect_to, so I will summarize the difference for myself.
-Render: Specify the view file directly. You do not have to go through other actions. Variables in actions that specify render can be used in other views ・ Redirect_to: Specify URL Transfer to another URL
render (folder / file) The first / is not required because it is a folder name
render("users/edit")
redirect_to ("/ URL / ~ / ~") First / Yes
redirect_to("/users/#{@user.id}")
-Render: controller → view -Redirect_to: controller-> URL-> route-> controller-> view
The process that render specifies a view file and displays it redirect_to is the same process as receiving an HTTP request on the browser
-Render: Used when you want to take over the previous data without updating -Redirect_to: Requires controller processing such as data deletion and update
Recommended Posts