Rails 多步骤模型创建

发布于 2024-10-09 19:21:02 字数 274 浏览 0 评论 0原文

在 Rails 中实现模型的多步骤创建的好方法是什么?我的意思是,用户不是填写一个长表单,而是填写一个部分,然后在另一页上填写下一部分。本质上,这是一个多部分表单,每个部分位于不同的页面上。

如何保存表单每个部分的用户输入?我也在现场进行验证;如何在 Rails 中处理验证,以便单独验证表单的每个部分? (如果我将所有验证放入模型中,表单将永远不会成功验证,因为用户看不到的字段永远不会被填写。是的,javascript 是一个选项;我想在 Rails 中处理验证,以便它即使禁用 javascript 也能工作)。

What is a good way to implement multistep creation of a model in rails? By this I mean, instead of having one long form, the user fills out one part, and then fills out the next part on another page. Essentially, this is a multi-part form with each part on a different page.

How do I save the user input for each part of the form? I am doing validations on the fields as well; how do I handle validation in Rails so that each part of the form is validated separately ? (If I put all of the validations in the model, the form will never validate successfully, as the fields that the user cannot see yet are never filled out. Yes, javascript is an option; I want to handle validation in Rails so that it will work even with javascript disabled).

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

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

发布评论

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

评论(2

热血少△年 2024-10-16 19:21:02

Ryan Bates 做了一个与此直接相关的截屏视频,我强烈建议您查看:

http://railscasts .com/episodes/217-multistep-forms

Ryan Bates did a screencast directly related to this, I highly recommend you check it out:

http://railscasts.com/episodes/217-multistep-forms

清晨说晚安 2024-10-16 19:21:02

魔法宝石就是为了做到这一点而设计的。非常方便。我的叉子:
https://github.com/paulschreiber/wizardly

请注意,它不适用于 Rails 3.x;它需要 Rails 2.3.x 或更早版本。

The wizardly gem is designed to do this. It's very handy. My fork:
https://github.com/paulschreiber/wizardly

Note that it does not work with Rails 3.x; it requires Rails 2.3.x or older.

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