我有一個助手接收一組附件集合,並嘗試計算圖像是否正方形。如何處理將項目傳遞給幫助者時的項目集合?
關於我有一個條件,如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)) }