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"
你有什么想法如何实现? 在此先感谢!