Rails:基于角色的用户的 DRY 视图
我很好奇现在 DRY 视图的最新技术是什么。我有一个已经发展了三年半的应用程序,而现在视图层并不是一个令人愉快的地方。
首先介绍一下背景,我有一个由多个不同用户组使用的应用程序,我需要添加更多内容。不同用户看到的内容之间存在大量重叠,但仍然有很多内容是每个组独有的。用户看到的细节内容和数量受到限制。这是基于标准角色的 Web 应用程序。
目前,该应用程序正在使用丑陋的混杂的部分(带有局部变量),以及使用部分、content_for 块和助手的部分,以及一大堆重复。
我正在寻找的是,人们现在在做什么来保持他们的观点干燥?
我开始研究 Cells (http://cells.rubyforge.org/),但我想知道还有什么可以解决这个问题。
您使用什么来实现复杂且基于角色的视图?
I'm curious what the state of the art is for DRY views these days. I've got an app that's been evolving for over three and a half years, and these days the view layer is not a happy place.
First a little background, I've got an app that is used by several different groups of users, and I need to add more. There is a significant amount of overlap between what different users see, but there's still a lot that is exclusive to each group. Users have restrictions what and how much detail they see. It's your standard role based web app.
Currently the app is using an ugly mishmash of partials (with local variables), and partials using partials, content_for blocks and helpers, and a whole bunch of duplication.
What I'm looking for is, what are people doing these days to keep their views DRY?
I started looking at Cells (http://cells.rubyforge.org/), but I wondered, what else is out there for solving this problem.
What are you using for complex and role-based views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我面临着同样的问题/挑战。我已经开始实现 Cell,但遇到了困难,“content_for”不受您期望的方式支持,并且无法使用单元视图将内容添加到主布局。
这是 Rails 中的一个限制/Cell 使用 Rails 的方式,而且看起来并不是真正可以规避的。
如果您可以忍受这个限制,我认为这是重复内容块的最佳解决方案。
对我来说,上述问题的最佳解决方案如下:
如果整个单元格需要在不同的内容块中呈现,则可以使用以下内容来获得一个不错的API:
将以下代码段放入application_helper.rb中:
在视图中使用
以在块的内容中呈现。
I'm facing the same problem/challenge. I've started implementing Cell but ran into a wall, 'content_for' is not supported in the way you'd expect and it is not possible to add content to the master layout with it using a cell view.
This is a limitation in Rails / the way Cell uses rails and is not really circumventable it seems.
If you can live with this limitation I think it is the best solution for repeated content blocks.
Slightly offtopic the best solution to the above problem for me is the following:
If the entire cell needs to be rendered in a different content block the following can be used to get a nice api:
Put the following piece of code in the application_helper.rb:
Use
in your views to render within a content for block.