多个资源的同一控制器/视图

发布于 2024-11-30 20:16:05 字数 606 浏览 1 评论 0原文

我有一个用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扬花落满肩 2024-12-07 20:16:05

您可能会更轻松地为从公共父级继承的每个特定对象类型使用一系列控制器。这样,大部分重复都可以在基类中,其中仅在子类中表达差异。

为了确保您的模板正确呈现,您可能必须指定它们的完整路径,否则它将查找自定义版本:

 def index
   # ...
   render(:template => 'parent/index')
 end

通常这是多余的,但在您的情况下您可能需要它,否则它将默认显示不存在的子项-首先是模板。

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:

 def index
   # ...
   render(:template => 'parent/index')
 end

Usually this is redundant, but in your case you may need it or it will default to showing the non-existent child-template first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文