If you’re using the rhtml templates, there are always going to be a
fair number of <% %> symbols to type. I use TextMate, which has
helpful key bindings for that. But some things that might help clean
things up a bit:
Try using form_for: Peak Obsession
Helpers/FormHelper.html#M000384
Try putting that select tag into a helper.
For example: (though my syntax might be incorrect as it’s late)
Obviously this is not very clean. I find it hard to read and having to
type so many times the same symbols is tedious
For the sake of clarity, I assume you’re not trying to drop all the <%
markup, but are in fact looking for a way to put the whole thing inside
a single <%.
In effect, can we convert <%= %> into something like print(…) so we
can embed <%= %> inside <% %> ?
For something as complicated as above, you may find helpers useful, but
even in a simple case:
<% for blah in blahs %>
<%= blah.foo %>
<% end %>
I’d prefer to do:
<%
for blah in blahs
print blah.foo
end
%>
Which would, as a side effect, facilate easy moving into a helper.
I’d like to know how to do this as well. Anyone with any ideas ?
Actually, I think what your proposing is really interesting.
For instance, this is how we’d loop a collection (lets say partials w/
collections are overkill here)
We’d normally write
<% for user in @users -%>
<%= user.name %>
<% end -%>
We could write.
<% for user in @users
= user.name + “ ”
end %>
Now, the problem with having erb syntax that allows that is we can get
all
non-mvc like temptations. Aka, mixing in our controller code with our
view.
But, then again, I think the second option is much more pretty. I mean,
the
lack of this is basically what requires -%>… so that you can keep from
messing up your response html.
Now, the problem with having erb syntax that allows that is we can get all
non-mvc like temptations. Aka, mixing in our controller code with our view.
But, then again, I think the second option is much more pretty. I mean, the
lack of this is basically what requires -%>… so that you can keep from
messing up your response html.
Maybe it’s worth exploring the possibility that the Java world got
something right. Custom tags, especially like those from Struts, go a
long way toward cleaning up the view.
Is one cleaner than the other? For simple things, probably not. But
for more complex views, I also have this nagging feeling of annoyance
at all the <% %> tags.
That’ll be the “really I’m private” underscore. How about using
helpers instead? Otherwise, give the Amrita plugin a try, or possibly
define a function like:
since there are 17 replies all containins <% %>s, i will say it again,
check out Markaby !!
its pretty damn near perfection in terms of minimizing the amount of
typing, let alone typing of < % >s, if you are able to mentally
visualize your pages layout from a handcoding perspective.
it has a few bugs, like i cant get instance variables created inside a
markaby template, to propagate to partials, without explicitly passing
them in via the :locals flag. and if you want to have a designer work on
your templates, dreamweaver etc will surely choke on them… but come on,
teach your designer to code