1. Conclusion </ b>
2. How to use </ b>
3. Why does such a difference occur? </ B>
4. What I learned from here </ b>
❶render
(i) I just want to specify a View file and display it
controller.rb
def
render '***(View file name).index(Action name) #---"a"
end
or
def
render :index(Action name) #---"b"
end
What is the difference between "a" and "b" a➡︎ I want to display the actions of different controllers b ➡︎ I want to display the action of the same controller that describes render It means that.
(ii) I want to use the same program in multiple html.erb files
python
<%= render 'public/error_messages', model: f.object %> #---Excerpt from my article
In the above case, when you enter empty in the index, new, show action, the message "Requirements have not been entered!" Is displayed. ( How to put out error bundling )
❷redirect_to
(i) I want to perform an action once through Controller processing
controller
def
redirect_to("/app/(View folder name)/(Action name.html.erb)")
end
or
def
redirect_to ****_****_path
end
In other words, it means specifying the URL.
The bottom line is whether there is a "Controller again" in between.
❶ render is for the movement of Controller ➡︎ View ❷ redirect_to is Controller ➡︎routes.rb (id based on URL) ➡︎Controller ➡︎View It will be a movement. If only render is used, it only displays the "just" page, so processing may be troublesome and an error may occur. Since redirect_to sandwiches the Controller once, the update / destory action can be performed without error.
Recommended Posts