2011-03-03 53 views
5

我有以下HAML书面采取了脚手架索引页的地方后阵列:如预期HAML呈现#each

%h1 Listing Races 

%table 
    %tr 
    %th Name 
    %th Date 
    %th Details 
    [email protected] do |race| 
    %tr 
     %td= race.name 
     %td= race.date 
     %td= race.details 
     %td= link_to 'Show', race 
     %td= link_to 'Edit', edit_race_path(race) 
     %td= link_to 'Destroy', race, :confirm => 'Are you sure?', :method => :delete 
%br 
= link_to 'New Race', new_race_path 

当页面呈现,表格打印出来,但事后,该阵列@races也被打印出来;例如:

[#<Race id: 1, name: "TestRace15", date: "2011-03-11 11:00:00", details: "Test Race to make sure that everything seems to wor...", created_at: "2011-03-03 00:16:09", updated_at: "2011-03-03 00:16:09">] 

我在做什么错误的HAML循环结构,或什么会导致数组被渲染?

回答

14

代字号(~)输出行的结果,该行是一个数组,因为Array#each返回原始数组。在此意义上,=~的行为相似;但是,~会保留=通常会剥去的空白。

您可能打算使用破折号(-),它运行代码但不输出表达式的结果。

See the HAML docs for more :)

+1

这就是问题所在。谢谢您的帮助! – ballpointcarrot 2011-03-03 17:04:11