Rails - 相同的模型/控制器,但不同的视图
我正在构建一个表单向导,引导用户完成已创建和部署的表单。模型和控制器应该保持不变,因为唯一改变的是视图(引导用户通过每个表单字段)。完成这项任务的最佳(也是最简单的,如果可能)方法是什么?
即使通过向导,一旦用户保存表单,它就会通过相同的模型和控制器保存到相同的数据库。通过进行一些研究,似乎可以通过创建一个新视图、创建一个扩展原始控制器的简单控制器并将新控制器路由到新视图来实现这一点。
任何建议都非常感激。谢谢!
I am constructing a form wizard that guides the user through a form that has already been created and deployed. The model and controller should stay the same as the only thing of change is the view (guiding the user through each form field). What is the best (and easiest, if possible) way of accomplishing this task?
Even through the wizard, once the user saves their form, it gets saved to the same database via the same model and controller. From doing a bit research it seems that this is possible by obviously creating a new view, create a simple controller that extends the original controller, and routing the new controller to the new view.
Any suggestions are really appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一些研究后,我找到了几种完成任务的方法:
After doing some research, I figured out a couple of ways to accomplish my task:
您绝对应该看这里:
http://railscasts.com/episodes/217-multistep-forms
否则,简短地回答一下,您可以告诉控制器的任何操作来渲染您想要的视图。这就是基本脚手架控制器中所做的事情:
You should definitely look here:
http://railscasts.com/episodes/217-multistep-forms
Otherwise, to answer shortly, you can tell any action of your controller to render ay view you want.That's what is done in the basic scaffold controller: