使用继承层次结构时在父控制器中呈现正确的操作 - Rails
我正在使用具有此单表继承层次结构的代码库:
BlogEntryWizardController < BlogEntriesController << CommonEntryController < ApplicationController
BlogEntryWizardController (BEWC) 使用与 BlogEntriesController (BEC) 相同的模型。 BEWC 和 BEC 之间唯一真正的区别是视图(一个只是另一个的教程向导)。在向导中提交表单后,它会不断将用户带到父级 BEC 的“显示”操作。这发生在 CommonEntryController (CEC) 中:
format.html {
render(:action => 'show')
}
这会调用 BEC 的 show 方法,但我需要它来调用 BEWC 中覆盖的 show 方法。在 CE 中是否有一种方法可以区分要适当调用的“显示”操作?
谢谢你的两分钱。
I am working with a code base that has this single table inheritance hierarchy:
BlogEntryWizardController < BlogEntriesController < CommonEntryController < ApplicationController
BlogEntryWizardController (BEWC) uses the same model that BlogEntriesController (BEC) uses. The only real difference between the BEWC and the BEC is the views (one is just a tutorial wizard of the other). Upon submitting the form within the wizard, it keeps taking the user to the "show" action of the BEC, the parent. This occurs within CommonEntryController (CEC):
format.html {
render(:action => 'show')
}
This invokes the show method of the BEC, but I need it to invoke the overriden show method within the BEWC. Is there a way of distinguishing within CE which "show" action to call appropriately?
Thanks for your two cents.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 BEC 中的“show”操作内部,将重定向发送到显示控制器:
仅仅这样做还不够,因为实例变量在控制器之间不是持久的。因此,您可以在会话中保存 BEC 实例变量,并在“显示”操作中在 BEWC 控制器中检索它。
Inside of the "show" action within BEC, send the redirect to the show controller:
Doing just that isn't enough as instance variables aren't persistent between controllers. So you can save your BEC instance variable within a session and retrieve it within your BEWC contoller in your "show" action.