2012-09-04 17 views
8

Proszę rozważyć następujący przykład:Jak przekazać obiekt hash do znacznika 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 

byłbym miło zmieścić to wszystko w prostym stwierdzeniem tak:

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

Odpowiedz

10

Tak, jest to możliwe, i były zbliżone:

%a{_user_link_params(current_user)} 

z HAML reference:

Na przykład, jeśli określona

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

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

następnie %sandwich{hash1, hash2, :delicious => true}/ by skompilować do:

<sandwich bread='whole wheat' delicious='true' filling='peanut butter and jelly' /> 
Powiązane problemy