Skip to content

Commit

Permalink
disabled user links
Browse files Browse the repository at this point in the history
  • Loading branch information
Blair Anderson committed Mar 8, 2015
1 parent a478988 commit 8cba4f0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/helpers/user_item_votes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ def render_votes_for_item(item)
link_to_upvote(item)
end
end

def render_link_to_user(user, options={})
if user.disabled?
user.username
else
link_to user.username, user, options
end
end
end
4 changes: 4 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ class Item < ActiveRecord::Base
end
end
validates :url, url: {allow_nil: true, allow_blank: true}


scope :active, -> { where(disabled: false) }
scope :newest, -> { order(score: :desc) }
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def item_votes
def to_param
username.downcase
end

def username
disabled? ? "[deleted]" : read_attribute(:username).downcase
end
end
2 changes: 1 addition & 1 deletion app/views/items/_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<small>
<%= render_votes_for_item(item) %>
<%= item.score %> points
by <%= link_to item.user.username, item.user %> <%= link_to "#{time_ago_in_words(item.created_at)} ago", item %>
by <%= render_link_to_user(item.user) %> <%= link_to "#{time_ago_in_words(item.created_at)} ago", item %>
| <%= link_to "#{item.comments_count} comments", item %>
</small>
</li>

0 comments on commit 8cba4f0

Please sign in to comment.