如何在MVC下创建一个简洁的RESTful向导? [英] How do I create a concise and RESTful wizard under MVC?

查看:16
本文介绍了如何在MVC下创建一个简洁的RESTful向导?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在构建应用程序时尽可能采用 RESTful,但我不确定的一件事是如何创建向导类型的工作流程,即 RESTful 和简洁.

I try to be as RESTful as possible in building applications but one thing that I'm never sure about is how to create a wizard-type work flow, be RESTful and concise.

以多页注册过程为例.

选项 1:我可以为每个步骤创建一个控制器,并在用户到达该步骤(或返回该步骤)时调用 new 或 edit .我以 step1_controller、step2_controller 等结尾...

Option 1: I can create a controller for each step and call new or edit when user gets to that step (or back to it). I end with step1_controller, step2_controller, etc...

选项 2: 我可以创建一个控制器,并使用参数、会话变量、状态机等来跟踪它们在注册过程中的位置.所以我有 signup_controller/step?id=1

Option 2: I can create a one controller and track where they are in the sign-up process with a param, session variable, state-machine - whatever. So I'd have signup_controller/step?id=1

第一个选项是严格的 REST,但不是很简洁,并以一些额外的控制器结束.第二个选项更简洁,但破坏了 REST,我愿意这样做,但我不会掉以轻心.

The first option is strictly REST, but not very concise and ends with some number of extra controllers. The second options is more concise, but breaks REST, which I'm willing to do, but I don't take it lightly.

有更好的选择吗?

我在 ruby​​ on rails 工作,但这个问题适用于其他 MVC 实现,如 ASP.NET MVC

I'm working in ruby on rails, but this question applies to other MVC implementations, like ASP.NET MVC

推荐答案

实际上,我不太关心在一次性向导中维护 REST.我认为 REST 是最重要的,它具有可重复的操作——您希望 url 基本上可以添加书签,这样无论您何时去那里,您都可以获得相同的数据视图.在多步骤向导中,您的依赖项无论如何都会破坏 REST 的这种观点.我的感觉是让单个控制器具有可能单独的操作或使用查询参数来指示您正在执行的步骤.无论如何,这就是我构建激活向导(需要多个步骤)的方式.

I'm actually less concerned about maintaining REST in a one-shot wizard. REST is most important, I think, with repeatable actions -- you want the url to be basically bookmarkable so that you get back the same view of the data regardless of when you go there. In a multi-step wizard you have dependencies that are going to break this perspective of REST anyway. My feeling is to have a single controller with potentially separate actions or using query parameters to indicate what step you are on. This is how I've structured my activation wizards (which require multiple steps) anyway.

这篇关于如何在MVC下创建一个简洁的RESTful向导?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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