move story tagging sorting into a function
This commit is contained in:
parent
d2e06ed127
commit
88709b5d04
|
@ -387,6 +387,10 @@ class Story < ActiveRecord::Base
|
|||
self.user_id, nil, false)
|
||||
end
|
||||
|
||||
def score
|
||||
upvotes - downvotes
|
||||
end
|
||||
|
||||
def short_id_path
|
||||
Rails.application.routes.url_helpers.root_path + "s/#{self.short_id}"
|
||||
end
|
||||
|
@ -395,8 +399,8 @@ class Story < ActiveRecord::Base
|
|||
Rails.application.root_url + "s/#{self.short_id}"
|
||||
end
|
||||
|
||||
def score
|
||||
upvotes - downvotes
|
||||
def sorted_taggings
|
||||
self.taggings.sort_by{|t| t.tag.tag }.sort_by{|t| t.tag.is_media?? -1 : 0 }
|
||||
end
|
||||
|
||||
def tagging_changes
|
||||
|
|
|
@ -23,8 +23,7 @@ class="story <%= story.vote == 1 ? "upvoted" : "" %> <%= story.vote == -1 ?
|
|||
</span>
|
||||
<% if story.can_be_seen_by_user?(@user) %>
|
||||
<span class="tags">
|
||||
<% story.taggings.sort_by{|t| t.tag.tag }.sort_by{|t|
|
||||
t.tag.is_media?? -1 : 0 }.each do |tagging| %>
|
||||
<% story.sorted_taggings.each do |tagging| %>
|
||||
<a href="<%= tag_path(tagging.tag.tag) %>"
|
||||
class="<%= tagging.tag.css_class %>"
|
||||
title="<%= tagging.tag.description %>"><%= tagging.tag.tag %></a>
|
||||
|
@ -40,8 +39,7 @@ class="story <%= story.vote == 1 ? "upvoted" : "" %> <%= story.vote == -1 ?
|
|||
<a href="<%= ms.url_or_comments_path %>"><%= ms.title %></a>
|
||||
</span>
|
||||
<span class="tags">
|
||||
<% ms.taggings.sort_by{|t| t.tag.tag }.sort_by{|t|
|
||||
t.tag.tag == "pdf" ? -1 : 0 }.each do |tagging| %>
|
||||
<% ms.sorted_taggings.each do |tagging| %>
|
||||
<a href="<%= tag_path(tagging.tag.tag) %>"
|
||||
class="<%= tagging.tag.css_class %>"
|
||||
title="<%= tagging.tag.description %>"><%= tagging.tag.tag %></a>
|
||||
|
|
Loading…
Reference in a new issue