我有一个助手接收一组附件集合并尝试计算图像是否为正方形。
在视图上,我有一个条件suggestion_grid_square?(@attachments)
,而辅助方法是。
(我已经简化了代码,让这个问题的问题更清楚)
def suggestion_grid_square?(*attachments)
suggestion_column_squares?(1,attachments)
end
def attachment_square?(attachment)
(attachment.file_height.to_f / attachment.file_width) <= 1
end
private
def suggestion_column_squares?(column,*attachments)
attachments.each do |attachment|
attachment_square?(attachment)
end
end
以下代码向我返回此错误:undefined method file_height for #<Array:0x007fa827e9af30>
app/helpers/suggestions_helper.rb:8:in `attachment_square?'
app/helpers/suggestions_helper.rb:15:in `block in suggestion_column_squares?'
知道为什么它没有收到该file_height
属性或我在这里做错了什么吗?
更新这是我创建集合的方式以及我在视图上调用助手的方式:
boutique_products = Product.by_most_recent.sold_or_designed_by(boutique).shuffle.first(4)
boutique_products.each { |product| (@attachments << product.default_attachment_or_first_attachment) }
.follow-boutique-grid{class: ("square-suggestion-grid" if suggestion_grid_square?(@attachments)) }