Rails - 查看对象迭代问题

发布于 2024-10-13 08:00:54 字数 479 浏览 1 评论 0原文

当我在视图中迭代一个对象时,它也会渲染对象本身。

我有:

@portfolio_queued = Artist.where(:state => 'portfolio_queued')

并且:

= for artist in @portfolio_queued
  %p
    = "#{artist.name}"
    %br
    = "#{artist.state}"

它正在渲染:

mauko
portfolio_queued

quiroga
portfolio_queued

quiroga
portfolio_queued
#<Artist:0x10652ca90>#<Artist:0x1065296b0>#<Artist:0x106529340>

有帮助吗?

When I iterate an object in my view, it renders the objects itself too.

I have:

@portfolio_queued = Artist.where(:state => 'portfolio_queued')

And:

= for artist in @portfolio_queued
  %p
    = "#{artist.name}"
    %br
    = "#{artist.state}"

And it's rendering:

mauko
portfolio_queued

quiroga
portfolio_queued

quiroga
portfolio_queued
#<Artist:0x10652ca90>#<Artist:0x1065296b0>#<Artist:0x106529340>

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽蝶幻影 2024-10-20 08:00:54

好的,只需替换

= for artist in @portfolio_queued

for

- for artist in @portfolio_queued

就可以了。

Ok, so just repalcing

= for artist in @portfolio_queued

for

- for artist in @portfolio_queued

does the trick.

以为你会在 2024-10-20 08:00:54

也许这只是个人喜好,但我发现很难阅读,并将其写为

= @portfolio_queued.each do |artist| 
  %p
     artist.name 
     %br
     artist.status

另外,再次个人喜好 - 对不是文本块的内容使用段落标签被认为是糟糕的 SEO/CSS; span、div 或表格单元格可能会更好。

Maybe this is just personal preference but I find that hard to read and would write it as

= @portfolio_queued.each do |artist| 
  %p
     artist.name 
     %br
     artist.status

Also, again personal preference - using paragraph tags for something that isn't a block of text is perceived as poor SEO/CSS; a span, div or table cell might be better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文