Ruby on Rails 中的粘性表单

发布于 2024-08-26 07:09:36 字数 144 浏览 3 评论 0原文

如何在 Rails 中制作粘性表单

谢谢

How can I make a sticky form in rails?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗忘曾经 2024-09-02 07:09:36

Rails 脚手架会自动执行此操作,对吧?你的行为举止不应与他们的有太大差异。

当您执行 <% form_for @user %> 时,所有用户的属性都会自动填充到该表单中。当您的用户验证失败且未保存时,将显示表单,并且 @user 仍然具有用户最初提交的所有属性;因此,表单字段会按预期自行填写。

Rails scaffolds do this automatically, right? Your form behavior shouldn't be departing much from theirs.

When you do <% form_for @user %>, all of the user's attributes are automatically filled in to that form. When your user fails to validate and does not save, the form is displayed, and @user still has all of the attributes that the user originally submitted; therefore, the form fields fill themselves out as intended.

浪漫人生路 2024-09-02 07:09:36

如果提交后未通过验证,您希望将用户发送回相同的操作而不重置它。要实现此目的,您需要在控制器中添加以下代码:

render :action => 'new'

或者

render :action => 'edit'

这两个代码通常分别位于创建和更新方法中。

If upon submission it does not pass validation you want to send the user back to the same action without resetting it. To achieve this you need the following code in your controller:

render :action => 'new'

or

render :action => 'edit'

These 2 would typically be in the create and update method respectively.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文