2012-09-04 19 views
8

perche questo esempio:Come passare un oggetto hash a un tag 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 

mi sarebbe bello per adattarsi a tutto questo in una semplice dichiarazione come la seguente:

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

risposta

10

Sì, è possibile, e si erano vicini:

%a{_user_link_params(current_user)} 

Dal HAML reference:

Per esempio, se si è definito

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

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

poi %sandwich{hash1, hash2, :delicious => true}/ sarebbe compilare in:

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