我在这里有这个过滤器用于标志名称。我想要做的是,如果我有多个标志的名称将内容合并在一起 检查所附的图像。我有两个服务器名称。我只想显示一个
请帮我解决这个问题!谢谢
<div class="categories">
<% @oferta.each do |o| %>
<ul class="cat">
<li class="pull-left"><h2><%= link_to o.offer,o %></h2><br><h4><%= o.description %></h4>
<div class="main">
<% if o.sigs.exists? %>
<div id="myBtnContainer">
<button class="btn active" onclick="filterSelection('o')">All</button>
<% for item in o.sigs %>
<button class="btn" onclick="filterSelection('<%= item.name %>')"><%= item.name%><br></button>
<% end %>
</div>
<div class="row">
<% for item in o.sigs %>
<div class="column <%= item.name %>">
<div class="content">
<%= image_tag item.image.url(), style: "width:100%"%>
<h4><br><%=link_to item.name,item %></h4>
<p><%= item.comment %></p>
</div>
</div>
<% end %><br><br>
</div>
<% end %><br>
</div>
<% end %>
</div>
这是oferta_controller.rb
class OfertaController < ApplicationController
before_action :find_ofertum, only: [:destroy,:edit,:update,:show]
def new
@ofertum= Ofertum.new
end
def create
@ofertum= Ofertum.new(ofertum_attributes)
if @ofertum.save
redirect_to oferta_path, notice: "Thank you... Your offer was created successfully."
else
flash.now[:error] = "Please correct the form"
redirect_to new_ofertum_path
end
end
def index
@oferta = Ofertum.all
end
def show
@ofertum = Ofertum.find(params[:id])
@sig = @ofertum.sigs.build
end
private
def ofertum_attributes
ofertum_attributes = params.require(:ofertum).permit([:offer,:description,:sign,:place,:sig])
end
def find_ofertum
@ofertum = Ofertum.find(params[:id])
end
end
在模型报价中
class Ofertum < ApplicationRecord
has_many :sigs
end
在 sig 模型中
class Sig < ApplicationRecord
belongs_to :ofertum
end
<% for item in o.sigs %>
<button class="btn" onclick="filterSelection('<%= item.name %>')"><%= item.name%><br></button>
<% end %>
而不是 for 循环尝试
<% o.sigs.pluck(:name).uniq.each do |name| %>
<button class="btn" onclick="filterSelection('<%= name %>')"><%= name %><br>/button>
<% end %>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句