After the process is finished (not finished) in the controller I have to think about which page to transition to, Use redirect_to at that time.
It is a method that can transition to the specified URL.
Basic writing
redirect_to "Redirect destination"
We will update this code as soon as it is available.
Specified by URL
redirect_to "https://qiita.com/japwork"
Specify by path name
redirect_to root_path
Specified by action name
redirect_to action: :index
Specified by action name of different controller
redirect_to controller: :post, action: :index
Go back to previous page
redirect_to :back
Redirect the same page
redirect_to request.referer
controller
redirect_to root_path, notice: 'Success'
view
<%= notice %>
redirect_to executes an action and displays the view corresponding to that action.
render displays the view without taking any action. If the view has an instance variable to be acquired by the action, an error will occur.
By using it together with the if statement, the transition destination can be changed and displayed depending on the result. You need to know the various methods. In addition to the above, there is also a status code, so if you are interested, please check it out.
Also, on twitter, technologies and ideas that are not uploaded to Qiita are also uploaded, so I would be grateful if you could follow me. Click here for details https://twitter.com/japwork
Recommended Posts