轨道最佳实践的多步骤形式? [英] rails best practice for a multistep form?
问题描述
我想在Rails 3中创建一个mutlistep表单。我已经观看了它的railscasts插曲,但我不觉得他在创建表单时使用了最佳做法。我觉得这是一个马虎的方式来完成任务。使用rails最佳实践创建多步表单的最佳方式是什么?解决方案
你的问题有点难以回答没有更多的信息,真正的答案将是一个详细的教程(像一个Railscast),而不是一个SO答案,但这里有一些想法让你在你的方式。
有两种主要的多步表单方法:
-
使用Javascript来逐位显示表格
-
创建单独的视图并使用
create
/update
用户从一个到另一个。
每种方法都有其优点,具体取决于您是否想要支持javascript,以及你的要求是关于在段之间保存数据。
1的优点
1的缺点
I want to create a mutlistep form in Rails 3. I've watched the railscasts episode on it, but I did not feel like he was using the best practice when creating the form. I felt like it was a sloppy way to accomplish the task. What is the best way to create a multistep form using the best practices in rails?
Your question is a little hard to answer without more information, and a true answer would be a detailed tutorial (like a Railscast) rather than a SO answer, but here's some thoughts to get you on your way.
There are two major approaches to multistep forms:
Use Javascript to display the form bit by bit
Create separate views and use
create
/update
or similar to route the user from one to the next.
There are advantages to each method, depending on whether you want to support javascript, and what your requirements are about saving data in between sections.
Advantages of 1
- Faster for the user to navigate from section to section (javascript hide/show is instantaneous)
- Data is easily accessible is the user wants to refer to an earlier section
- Simpler controller actions
Disadvantages of 1
- Will not work for users who are not running javascript (and no progressive enhancement is really possible here other than displaying the form as a huge chunk).
- Will require you to provide javascript-based navigation to move from section to section (only a disadvantage if you're new to .js)
- Will require AJAX if you want to save the user's information between steps.
- Without AJAX and javascript, the user is at the risk of losing a lot of entry if the user accidentally pressing the back button, etc.
这篇关于轨道最佳实践的多步骤形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!