Forum: Ruby on Rails Helpers and html/code separation

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7b74ccf93dde7dd2ac5d2980d14fdc7b?d=identicon&s=25 Paul Lynch (plynchnlm)
on 2007-04-21 02:10
(Received via mailing list)
To what extent should one try to keep strings of HTML out of helper
functions?  Both .rhtml and helpers are in the view layer, so it would
seem okay to include HTML in the helper function, which is after all
trying to construct something to put the returned page.  A cleaner
separation could be obtained by having the helper function use
partials-- but that could lead to a proliferation of very simple
partials, and I wonder about the performance of having ERB code in
an .rhtml file calling an helper rendering a partial, which might call
another function in the helper....

Does anyone have a good rule of thumb for when HTML code should be
moved into a partial?

Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-04-21 02:58
(Received via mailing list)
Paul E. G. Lynch wrote:

> Does anyone have a good rule of thumb for when HTML code should be
> moved into a partial?

Place HTML wherever you like so long as it passes these checks, in

 - your colleagues approve
 - the HTML passes all tests
 - the code is clear and understandable
 - the code has the least possible duplication
 - the code has minimal methods & classes

Put the HTML, or whatever, wherever you like, so long as all your code
passes all those checks.

Attempting to keep the HTML out of the model or controller layers is
essentially a mind game - can we challenge ourselves to reduce excesses?
Keeping methods short is a similar mind game. If you are indeed writing
clean code, then the actual home site of various effects is less
and of course much HTML will naturally gravitate to the View.

When I put HTML in the model, I generate it with Builder::XmlMarkup, so
easy to refactor.

This topic is locked and can not be replied to.