Rails:“新"功能如何实现?称为“创建"的动作行动? [英] Rails : How does "new" action called "create" action?
问题描述
我正在按照本教程 http://guides.rubyonrails.org/v3.2.13 /getting_started.html 来构建3.2.13版的Rails应用.如果转到第6.9节,将找到控制器并查看用于创建新帖子的视图.在这里,我不了解如何将@post
变量从new
动作传递到create
动作,以及create
函数在哪里被调用?另外,在处理edit
和更新actions
时,我遇到了相同的问题.请通过这个指导我.
I am following this tutorial http://guides.rubyonrails.org/v3.2.13/getting_started.html to build my rails app in version 3.2.13 . If you go to the section 6.9 you will find controller and view for creating new posts . Here I do not get how @post
variable is passed from new
action to create
action and where is create
function called ? Also , I faced the same problem while working on edit
and update actions
. Please guide me through this .
推荐答案
它没有传递给create
动作,而是使用从new
动作显示的表单中传递的参数再次实例化.
It's not passed to create
action, it's instantiated again with params you pass from the form displayed with new
action.
create
操作通过POST请求调用到config/routes.rb中指定的路径,从而导致特定的控制器和操作.
create
action is called with POST request to the path specified in config/routes.rb, leading to specific controller and action.
这篇关于Rails:“新"功能如何实现?称为“创建"的动作行动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!