move story tagging sorting into a function

This commit is contained in:
joshua stein 2015-01-05 12:06:24 -06:00
parent d2e06ed127
commit 88709b5d04
2 changed files with 8 additions and 6 deletions

View file

@ -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

View file

@ -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>