7 ms·
I'm finding that it's a lot cleaner to use with Javascript. For example, say you have an array of items and you want to create a fieldset for each item, and add
by AlwaysBCoding 14y ago
I'm finding that it's a lot cleaner to use with Javascript. For example, say you have an array of items and you want to create a fieldset for each item, and add an attribute of "data-id", and "data-category" to each fieldset so you can grab them with jQuery later on.
In HAML all you have to do is this...
- @items.each do |item|
%fieldset{:data => {:id => item.id, :category => item.category}}
===
In ERB the equivalent would be...
<% @items.each do |item| %>
<fieldset data-id="<%= item.id %>" data-category="<%= item.category %>">
</fieldset>
<% end %>
===
It's a lot cleaner in HAML, especially extrapolated out over larger views.
- rhizome 14y agoLook into `tag`: http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag http://api.rubyonrails.org/classes/ActionView/Helpers/TagHel... ERB view: <%= render @items %> items/_item.html.erb: <%= tag "fieldset", data: { id: item.id, category: item.category } %>