我有一個模型,每個資產都有一個main_image,而在附件模型中,每個資產只能有一個真值。我想知道是否有一種方法來拉這個記錄沒有循環通過每個記錄,看看main_image設置爲true或false。Rails得到一個沒有循環的記錄
澄清:
我可以找到使用下面的代碼值:
<% @asset.attachments.each_with_index do |attachment, i| %>
<%= image_tag(attachment.attachment.s_640_480) if !attachment.main_image.nil? && attachment.main_image%>
<%end%>
,但是,我想知道如何做到這一點沒有環...... 我不知道如何澄清任何更多...但這樣的:
<%= image_tag(@attachment.where_main_image.s_640_480) %>
我知道這是行不通的,但基本上是概念
我想我差不多明白的問題,但你可以張貼一些簡單的代碼示例,所以我們會確定嗎? – Arsen7
你能澄清你的問題嗎?目前,我無法理解,你有什麼設置和你想要什麼。 – rubish
@ Arsen7 Gupta我試圖澄清,不好意思,如果它仍然令人困惑。 –