轨道最佳实践的多步骤形式? [英] rails best practice for a multistep form?

查看:127
本文介绍了轨道最佳实践的多步骤形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Rails 3中创建一个mutlistep表单。我已经观看了它的railscasts插曲,但我不觉得他在创建表单时使用了最佳做法。我觉得这是一个马虎的方式来完成任务。使用rails最佳实践创建多步表单的最佳方式是什么?解决方案

你的问题有点难以回答没有更多的信息,真正的答案将是一个详细的教程(像一个Railscast),而不是一个SO答案,但这里有一些想法让你在你的方式。



有两种主要的多步表单方法:


  1. 使用Javascript来逐位显示表格


  2. 创建单独的视图并使用 create / update 用户从一个到另一个。


每种方法都有其优点,具体取决于您是否想要支持javascript,以及你的要求是关于在段之间保存数据。



1的优点


  • 用户可以更快地从一个区段导航到一个区段(javascript hide / show是即时的)

  • 数据易于访问,用户希望引用前面的部分
  • 简单的控制器操作
  • >


1的缺点


  • 不适用于用户谁没有运行javascript(除了将表单显示为一个巨大的块以外,没有渐进式增强功能是真正可行的)。

  • 需要您提供基于JavaScript的导航以从部分移动到如果你想在步骤之间保存用户信息,需要使用AJAX。

  • 没有AJAX和javascript,如果用户不小心按下后退按钮等,用户可能会失去很多输入。


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:

  1. Use Javascript to display the form bit by bit

  2. 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屋!

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