Javascript 如何在RubyonRails中合并列中的重复项?
我这里有一个符号名过滤器。我想做的是,如果我有一个以上的名称的标志合并在一起的内容 检查附加的图像。我有两个姓。我只想展示一个 请帮帮我!谢谢Javascript 如何在RubyonRails中合并列中的重复项?,javascript,ruby-on-rails,ruby,model-view-controller,filter,Javascript,Ruby On Rails,Ruby,Model View Controller,Filter,我这里有一个符号名过滤器。我想做的是,如果我有一个以上的名称的标志合并在一起的内容 检查附加的图像。我有两个姓。我只想展示一个 请帮帮我!谢谢 <div class="categories"> <% @oferta.each do |o| %> <ul class="cat"> <li class="pull-left"><h2><%= link_to o.offer,o %>
<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
在oferta模型中
class Ofertum < ApplicationRecord
has_many :sigs
end
在sig模型中
class Sig < ApplicationRecord
belongs_to :ofertum
end
而不是循环尝试
/按钮>
合并结果是什么??它将显示第一个或第二个??您可以这样做,Ofertum.all.group_by&:name使用这个@oferta=Ofertum。选择'distinct on sign*',它将获取uniq名称。如果不是,请告诉我working@ofertahave sig和每个sig都有名称、图像等。当名称重复时,我希望在过滤器中合并名称。这些解决方案都不管用太感谢你了Teja,在花了两天时间之后终于管用了: