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