我想要达到的目标:使用isotope.js从我的Gallery.tag动态创建分类器
要做到这一点,我需要
<h2>中显示的标记(使用globalize 3进行翻译)我不能在这两种情况下都使用@galleries,因为在切换语言时,它会将汉字输出到我的.class,从而破坏了分类器。因此,我创建了两个数组,并将它们与zip结合在一起,并将它们循环起来。
我试着按字母顺序对它们进行排序,但我相应的中文标签并没有按照我的英文顺序排序。
图库/index.html.erb
<% @uniq_test = [] %>
<% @galleries_order.each do |gallery| %>
<% next if @uniq_test.include?(gallery.tag) %>
<% @uniq_test << gallery.tag %>
<% end %>
<% @sorters = @sorters.map(&:downcase).sort! %>
<% @uniq_test = @uniq_test.map(&:downcase).sort! %>
<% @uniq_sorters = @uniq_test.zip(@sorters) %>
<div class="main">
<div class="gallery-select-wrapper">
<div class="sort-gallery-buttons animated slideInLeft text-center">
<h2 id="recent"class="recent"><%= t"galleries.sorter.recent"%></h2>
<% @uniq_sorters.each do |uniq, sorter| %>
<% if sorter != nil %>
<% str = "<h2 class='" + sorter + "'" + "id='"+ sorter + "'>"%>
<%= str.html_safe + uniq + "</h2>".html_safe %>
<% end %>
<% end %>
</div>
</div>
</div>管制员/画廊。
def index
@galleries = Gallery.all.order("created_at DESC")
@galleries_order = Gallery.all.order("title ASC")
@sorters = Gallery.uniq.pluck(:tag)
gon.tags = Gallery.uniq.pluck(:tag)
end类别是国家,主题,项目,战争类别是主題,國家,戰爭,項目<-当前(在en =主题,国家,战争,项目)我的类别是國家,主題,項目,戰爭<-目标(与en相同)
简而言之,我想要中文翻译遵循我的英文字母顺序。


发布于 2016-03-26 15:35:32
解决了!简而言之,要用globalize3::翻译模型来分类,最好的方法是按:id排序,或者在我的例子中按:created_at排序,而不是按标题排序,而我必须处理的是找到一种对汉字排序的方法!因为我并不特别关心这些术语是否按字母顺序排列,只要它们是同步的,我就很高兴。
就这么简单,我肯定是想得太多了!
图库/index.html
<% @array = [] %>
<% @test.each do |test| %>
<% next if @array.include?(test.tag) %>
<% @array << test.tag %>
<% end %>
<% @array_en = [] %>
<% @test.each do |test| %>
<% next if @array_en.include?(test.tag_en) %>
<% @array_en << test.tag_en %>
<% end %>
<% @combined_array = @array.zip(@array_en) %>
<div class="main">
<div class="gallery-select-wrapper">
<div class="sort-gallery-buttons animated slideInLeft text-center">
<h2 id="recent"class="recent"><%= t"galleries.sorter.recent"%></h2>
<% @combined_array.each do |uniq, sorter| %>
<% if sorter != nil %>
<% str = "<h2 class='" + sorter + "'" + "id='"+ sorter + "'>"%>
<%= str.html_safe + uniq + "</h2>".html_safe %>
<% end %>
<% end %>
</div>
</div>
</div>管制员/画廊。
@test = Gallery.all.sort { |p1, p2| p1.created_at <=> p2.created_at }https://stackoverflow.com/questions/36232094
复制相似问题