diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index c5e60479..99a8452f 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -87,8 +87,9 @@ def show_more skip_authorization page = params[:page] + current_user_id = (current_user.nil?) ? nil : current_user.id books = Book - .most_recent_with_content(page) + .most_recent_with_content(current_user_id, page) .map do |book| BookSerializer.new(book) end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index e5503949..7b2c103f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -6,7 +6,7 @@ def index @user = current_user @hashedEmail = Digest::MD5.hexdigest(@user.email) @books = Book - .most_recent_with_content + .most_recent_with_content(@user.id) .map do |book| BookSerializer.new(book) end diff --git a/app/models/book.rb b/app/models/book.rb index 39c42c74..84e6226d 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -10,8 +10,10 @@ class Book < ActiveRecord::Base after_create :send_admin_notification self.per_page = 10 - def self.most_recent_with_content(page = 1) - joins(:phrase_pairs) + def self.most_recent_with_content(current_user_id = nil, page = 1) + where + .not(user_id: current_user_id) + .joins(:phrase_pairs) .uniq .includes(:user) .order("created_at DESC")