Cleaner Erb Syntax #
I know alot of you out there are using Erb syntax for your rthtml
files in Rails. Erb is also used in Hobix and Soks. Well, did you know that you can mark Erb lines with an initial percent symbol, saving yourself the messiness of open and close brackets?
This:
<% entries.each do |e| %> <div class="entryTitle"><%= e.title %></div> <div class="entryBody"> <%= e.content.to_html %> </div> <% end %>
Can also be expressed as:
% entries.each do |e| <div class="entryTitle"><%= e.title %></div> <div class="entryBody"> <%= e.content.to_html %> </div> % end
I find it especially nice for loops, since I can easily browse the file for those marked lines. (More on Erb syntax in the docs.)
Asenchi
Fantastic, I didn’t know this. Very handy.
the blank'd cavlier fox
Can u also do
%= e.title
?
undees
What do you do if you need a line with a percent?
% puts '%'
, I guess…nathaniel
undees: You can just do two percents.
nathaniel
It appears that rails does not have this enabled. Maybe somebody should submit a patch…
dav
Yeah, this didn’t work in rails unfortunately
Comments are closed for this entry.