Deep digging, memo
· Call render and ** return to browser ** create complete ** response ** -Call redirect_to and send ** HTTP redirect code status ** to ** browser **
Summarize briefly render method ... Specify "** view file " to be displayed redirect method ... Specify " URL (HTTP request method) **"
As explained above, the View ** you want to display in ** Action The method to specify
In that Action, what is stored as @ ~ (instance variable) is It is possible to call from View with Ruby syntax
View formats that can be called include ".html" and ".html.erb".
You can also output text format, JSON, XML
Simple movement of ** controller → view ** Specify the view file you want to display, I'm just displaying it
To "resend" the request again to another URL Method for issuing commands to the browser
Send an HTTP request to the server The user will see the HTML returned from it
As a side note, in Rails' redirect_to method ** HTTP method is fixed to "GET" **
So ** Cannot redirect ** with POST request etc. **
controller → URL → route → controller → view
And you can see that it works with a completely different structure from the render method
・ If you fail to log in or enter = ** I just want to display an error **
→ render
method
-When data update or deletion is required = ** Controller processing ** is required
→ redirect_to
method
・ Only one view can be returned from one Action
rb/app/controller/○○controller.rb
class ○○Controller < ApplicationController
def create
~~
if ~~
~~
render "index"
end
render "new" ☓
redirect_to "new" ○
end
end
https://railsguides.jp/layouts_and_rendering.html https://qiita.com/1ulce/items/282cccba1e44158489c8 https://qiita.com/kanpe777/items/c5154b58c852855deefc https://easyramble.com/cannot-post-redirect-on-rails.html https://stackoverflow.com/questions/985596/redirect-to-using-post-in-rails
Recommended Posts