2012-09-04 35 views
8

Por favor, considere este ejemplo:cómo pasar un objeto hash a una etiqueta HAML

- user_links_params = _user_link_params(current_user) 

%a{ :'data-msgstore-path' => user_links_params[:'data-msgstore-path'], 
    :'data-user_id' => user_links_params[:'data-user_id'], 
    :class => user_links_params[:class], 
} 
/too many html tags and stuff to fit in a simple link_to 

que sería bueno para encajar todo esto en una simple declaración como la siguiente:

%a[_user_link_params(current_user)] 
/too many html tags and stuff to fit in a simple link_to 

Respuesta

10

Sí, que es posible, y que estaban cerca:

%a{_user_link_params(current_user)} 

Desde el HAML reference:

Por ejemplo, si ha definido

def hash1 
    {:bread => 'white', :filling => 'peanut butter and jelly'} 
end 

def hash2 
    {:bread => 'whole wheat'} 
end 

continuación %sandwich{hash1, hash2, :delicious => true}/ compile a:

<sandwich bread='whole wheat' delicious='true' filling='peanut butter and jelly' /> 
Cuestiones relacionadas