如何使用HAML迭代数组?

mrb*_*000 5 ruby iteration

我有一个HAML布局(layout.haml)

- @fonts.each do |font|
  %link{:href=>"//fonts.googleapis.com/css?family={font}",:rel=>"stylesheet",:type=>"text/css"}
Run Code Online (Sandbox Code Playgroud)

我在HAML模板index.html.haml中有这个

- @fonts = ['Lato:400,300,100','Droid+Serif:700,400'];
Run Code Online (Sandbox Code Playgroud)

当我编译时,我得到这个:

<link href='//fonts.googleapis.com/css?family={font}' rel='stylesheet' type='text/css' />
<link href='//fonts.googleapis.com/css?family={font}' rel='stylesheet' type='text/css' />
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Ser*_*sev 7

你忘记了哈希符号.

- @fonts.each do |font|
  %link{:href=>"//fonts.googleapis.com/css?family=#{font}",:rel=>"stylesheet",:type=>"text/css"}
                                                  ^ here
Run Code Online (Sandbox Code Playgroud)