我正在尝试添加一个可点击的链接,该链接将使用 has_scope gem 按字母顺序对链接页面进行排序。我究竟会在我的观点中提出什么来完成这项工作?
模型链接.rb
scope :abc, -> { order("links.title ASC") }
Links_Controller.rb
has_scope :abc
def index
@links = apply_scopes(Link).all
end
索引.html.erb
<div id="links-wrapper">
<%= render partial: "shared/link", collection: @links %>
</div>
_link.html.erb
<div class="link">
<a class="link-title" href="<%= link.url %>" target="_blank"><%= link.title %></a>
<div class="link-printed-url"><%= link.url %></div>
<p class="link-description"><%= link.description %></p>
<div class="link-tags">
<% link.tags.any? %>
<% link.tags.each do |tag| %>
<span class="label-tag">
<%= link_to tag_path(tag) do %>
#<%= tag.name %>
<% end %>
</span>
<% end %>
</div>
</div>