如何防止对象id打印到屏幕

时间:2011-06-27 06:31:23

标签: ruby-on-rails ruby haml

如何使用HAML模板从呈现对象ID中阻止视图中的部分表单? 例如,show.html.haml Users =render 'shortlists'包含%p Shortlists: = @shortlists.each do |s| = render :partial => 'shortlists', :locals => { :s => s } %p 的候选人列表:

Shortlists:
 Shortlist A has 0 items
 Shortlist B has 5 items
"#<Shortlist:0xa95fa38>#<Shortlist:0xa95f54c>"

我在屏幕上看到的是:

"#<Shortlist:0xa95fa38>#<Shortlist:0xa95f54c>"

如何阻止

{{1}}

来自渲染?

2 个答案:

答案 0 :(得分:5)

=前面的@shortlists.each更改为-

Relevant documentation

答案 1 :(得分:1)

您可以进一步压缩代码:

# view.html.haml
= render @shortlists

然后,在_shortlist.html.haml中,可以通过名为Shortlist

的变量访问当前迭代的shortlist实例