From 8cba4f0c78158bb8692516f517fe3018e883b93e Mon Sep 17 00:00:00 2001 From: Blair Anderson Date: Sat, 7 Mar 2015 18:29:39 -0800 Subject: [PATCH] disabled user links --- app/helpers/user_item_votes_helper.rb | 8 ++++++++ app/models/item.rb | 4 ++++ app/models/user.rb | 4 ++++ app/views/items/_item.html.erb | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/helpers/user_item_votes_helper.rb b/app/helpers/user_item_votes_helper.rb index b8a2e20..eb1c6c7 100644 --- a/app/helpers/user_item_votes_helper.rb +++ b/app/helpers/user_item_votes_helper.rb @@ -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 diff --git a/app/models/item.rb b/app/models/item.rb index 61708bb..ce6e0ca 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 1289c26..b6eafd8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,4 +18,8 @@ def item_votes def to_param username.downcase end + + def username + disabled? ? "[deleted]" : read_attribute(:username).downcase + end end diff --git a/app/views/items/_item.html.erb b/app/views/items/_item.html.erb index 09884b8..34f8e61 100644 --- a/app/views/items/_item.html.erb +++ b/app/views/items/_item.html.erb @@ -10,7 +10,7 @@ <%= 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 %>