私が達成したいこと:私からisotope.jsを使用してカテゴリソーターを動的に作成しますGallery.tag
それをするために私はする必要があります
- 私のhtml .classの小文字の一意のタグをループアウトします
- タグをループアウトして (翻訳に globalize 3 を使用)、
<h2>
@galleries
言語を切り替えると、中国語の文字が .class に出力され、ソーターが壊れるため、両方のケースに使用できません。したがって、2 つの配列を作成し、それらを 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>
コントローラー/ギャラリー.rb
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 カテゴリは [country, theme, project, war] zh カテゴリは [主題,國家, 戰爭, 項目] <-- current (in en = theme, country, war, project) 私のカテゴリは [國家, 主題, 項目,戰爭] <-- ゴール (en と同じ)
一言で言えば、中国語の翻訳を英語のアルファベット順にしたいのです。