Restful Rails编辑与更新 [英] Restful Rails Edit vs Update

查看:81
本文介绍了Restful Rails编辑与更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编辑条目之后,我试图重定向到另一个页面,我认为它正在使用更新代码,因为您正在更新数据库。我花了一些时间才意识到我在控制器中使用了错误的动作。有人可以解释一下编辑和更新的工作方式。为什么会有两种不同的动作?它们之间有什么区别?

I was trying to redirect to a different page after editing an entry, I assumed that it was using the update code because you are updating the database. It took me some time to realise that I was using the wrong action in the controller. Can someone please explain how edit and update work. Why are there two different actions? what are the differences between them?

推荐答案

编辑操作负责呈现视图

更新操作负责与模型进行交互(数据库更新等)

update action is responsible for interacting with the model (db updates etc)

如果您运行耙路,您会看到动词和动作之间的区别。通常,提交表单时使用创建/更新操作。这与new和edit动作不同,因为它们用于呈现视图(显示要提交的表单)。

If you run rake routes you will see the difference between the verb and the action. Typically, the create/update actions are used when submitting a form. This differs from the new and edit actions as these are used to render the view (that displays the form to be submitted).

这篇关于Restful Rails编辑与更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆