开发者

Weird problem: collection object displaying in view?

开发者 https://www.devze.com 2023-02-23 14:19 出处:网络
When I run the following code in the view: - if @object.winner.present? && @object.winner.prizes.any?

When I run the following code in the view:

- if @object.winner.present? && @object.winner.prizes.any?
  %ul
    = 开发者_开发问答@object.winner.prizes.each do |p|
      %li= p.description.html_safe

It's returning this:

li prize1
li prize2
li prize3
...
[#<Prize object...> ... ]

Does anyone know why it is listing the @object.winner.prizes collection in the view directly after the last @object.winner.prizes object is displayed?

Extremely baffled! I'm using Rails v3.0.6


This is because you're using = when you should be using - to iterate over the objects:

- @object.winner.prizes.each do |p|
0

精彩评论

暂无评论...
验证码 换一张
取 消