I am specifically referring to the conditionals in the above code. They
don’t look very bad. But still, Something is definitely off, this can
look better. But how?
would love to hear some comments, how do you guys handle such cases in
code?
The ones that control business logic should refactor into the models,
and the
ones that control view logic (such as a style= tag) should refactor into
helpers.
Next, for larger extents of non-DRY RHTML code, use partials.
>
Going in the other direction, feel free to put the <%=%> inside the
style=’’.
Then it’s safely empty if it’s nothing.
Also always follow a perfect “symetry” rule. You don’t break it here,
but
abusing partials and <%=%> might lead to that. Always have the < in the
same
code region as its >, the same for " and " on both sides of an attribute
value,
and balanced tags like
and
. Don’t move one of those in a
partial or
something if you can help it!
And test the snot out of your views with assert_select and assert_ypath.
The
former gives a coarse but complete view of your HTML, and the latter is
as
precise as advanced XPath statements can get.