多个资源的同一控制器/视图
我有一个用 Rails 编写的工作流程应用程序,并且用户将经历许多提示。当“继续”这些提示/手动操作时,将针对工作流模型存储时间戳。
代码看起来像这样
class Workflow < ActiveRecord::Base
end
class OpenBook < ActiveRecord::Base
belongs_to :workflow, :polymorphic => true
end
class ReadFirstPage <
belongs_to :workflow, :polymorphic => true
end
目前每个工作流程项( OpenBook
)都会吐出一些文本(在模型中设置)和视图上的前进/后退按钮。这些工作项的控制器也执行类似的操作(新建、完成、编辑、继续、倒回)。
理想情况下,我想只使用相同的控制器和视图,然后更改模型。我可以对路线做些什么吗?
资源:open_books,:控制器=> “workflow_item”
我不确定如何在控制器中获得正确的分配。
或者我只是这样做完全错误,我应该使用助手?
I have a workflow app written in Rails and there are a number of prompts which the user will go through. When these prompts/manual actions are "proceeded" a time stamp is stored against the a workflow model.
Code looks something like so
class Workflow < ActiveRecord::Base
end
class OpenBook < ActiveRecord::Base
belongs_to :workflow, :polymorphic => true
end
class ReadFirstPage <
belongs_to :workflow, :polymorphic => true
end
At the moment each workflow item ( OpenBook
) and spits out a bit of text (set in the model) and a forward / backward button on the view. The controllers for these workitems also do the similar things (new, done, edit, proceed, rewind).
Ideally I would like to just use the same controller and views and just change the model. Is theer something I can do with the routes eg?
resources :open_books, :controller => "workflow_item"
Im not sure how I would go about getting the correct assignments in the controller.
Or am I just doing this completely wrong and I should be using helpers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会更轻松地为从公共父级继承的每个特定对象类型使用一系列控制器。这样,大部分重复都可以在基类中,其中仅在子类中表达差异。
为了确保您的模板正确呈现,您可能必须指定它们的完整路径,否则它将查找自定义版本:
通常这是多余的,但在您的情况下您可能需要它,否则它将默认显示不存在的子项-首先是模板。
You might have an easier time using a series of controllers for each specific object type that inherit from a common parent. That way most of the duplication can be in the base class where only the differences are expressed in the children.
To ensure your templates are rendered correctly, you may have to specify the full path to them or it will look for customized versions:
Usually this is redundant, but in your case you may need it or it will default to showing the non-existent child-template first.