0
我很努力與一個image_tag添加一個.where子句。我們的目標是在current_user.brand
等於現有品牌時展示Brand品牌的品牌形象。Rails:回形針寶石/ where-clause裏面image_tag
這裏是我的意見代碼:
<%= image_tag ((Brand.where(company: current_user.brand)).logo.url(:thumb)) %>
但是,這是行不通的。我得到這個錯誤:
undefined method `logo' for Brand::ActiveRecord_Relation:0x007ffd06dc2458
在品牌索引頁面本身,我可以告訴這個標誌:
<% @brands.each do |brand| %>
<%= image_tag brand.logo.url(:thumb) %>
<% end %>
爲品牌表中的DB-方案:
t.string "logo_file_name"
t.string "logo_content_type"
t.integer "logo_file_size"
t.datetime "logo_updated_at"
你有什麼想法如何實現? 在此先感謝!