0
我只想在頁面上顯示facebook url,twitter url。表中鏈接了大約40個網址,用於不同的社交網絡。如何快速從列表中選擇對應於數組元素的項目
我的代碼:
<ul class="icons-bar icons-bar_socials icons-bar_socials_profile">
<% @freelancer.links.each do |link| %>
<% if link.messenger_type.title == "facebook" %>
<li class="icons-bar__item">
<%= link_to link.url, link.url, class: "icons-bar__icon icon_faceebook" %>
</li>
<% end %>
<% if link.messenger_type.title == "twitter" %>
<li class="icons-bar__item">
<%= link_to link.url, link.url, class: "icons-bar__icon icon_twitter" %>
</li>
<% end %>
</ul>
list.rb
# == Schema Information
#
# Table name: links
#
# id :integer not null, primary key
# url :string
# freelancer_id :integer
# messenger_type_id :integer
#
# Indexes
#
# index_links_on_freelancer_id (freelancer_id)
# index_links_on_messenger_type_id (messenger_type_id)
#
class Link < ApplicationRecord
belongs_to :freelancer
belongs_to :messenger_type
end
messenger_type.rb
# == Schema Information
#
# Table name: messenger_types
#
# id :integer not null, primary key
# title :string
# created_at :datetime not null
# updated_at :datetime not null
#
class MessengerType < ApplicationRecord
has_many :links
end
我不喜歡這樣的方式。用什麼來實現這個任務更優雅的方式