Rails 多步骤模型创建
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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
魔法宝石就是为了做到这一点而设计的。非常方便。我的叉子:
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.