Nombre de clase dinámico en HAML
¿Hay una mejor manera de convertir lo siguiente a HAML?
<% flash.each do |key, value| %>
<div class="flash <%= key %>"><%= value %></div>
<% end %>
Lo mejor que puedo hacer es:
- flash.each do |key, value|
%div{:class => "flash " + key.to_s}= value
Pero parece incómodo. Y .flash#{ key}= value
no parece estar bien?!?
22
3 answers
Si estás buscando algo cada vez más conciso, puedes hacer esto ahora en haml:
- flash.each do |key, value|
.flash(class=key)= value
19
Author: gunn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-16 11:21:17
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-16 11:21:17
Un poco mejor:
- flash.each do |key, value|
.flash{:class => key}= value
12
Author: bowsersenior,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-09 18:12:59
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-12-09 18:12:59
Añadiendo una variación sobre el tema:
Este erb
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
Podría ser
=flash.each do |key, value|
.alert{:class => "alert-#{key}"}
=value
Similar a ¿Cómo hago id dinámicos en Haml?
7
Author: Asaf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:21
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:10:21