Developing helper functions that generate HTML: sh

2019-07-06 22:55发布

问题:

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 :-)