Developing helper functions that generate HTML: should I rather use nested content_tag()s or partials?

爷,独闯天下 提交于 2019-12-10 21:25:37

问题


I'm at the start of developing a Rails engine (and gem) that should provide many small helper functions that generate HTML for views.

Now I wonder whether it's advisable to rely on the use of many nested content_tag calls to generate the HTML, or if it's more pragmatic to just rely on partials.

In my opinion, the first approach may be a bit cleaner (but slower in performance), but the 2nd approach seems much easier to do, so I guess I will favor the 2nd one. What do you guys think?


回答1:


many nested content_tag calls

does not sound as if you should be doing this in a helper. 1 or 2 levels of tags is my personal limit, above that I go for the partial.

Thats just my feeling, no theory involved here :-)



来源:https://stackoverflow.com/questions/12530692/developing-helper-functions-that-generate-html-should-i-rather-use-nested-conte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!