diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 5c29d7c97..f9052de8a 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -162,7 +162,8 @@ class HacksController < ApplicationController if params[:come_from] hacks = Hack.select(select_sql).mine(current_user.id) else - hacks = Hack.select(select_sql).published.opening + # 全部包括已经发布的,和我的未发布的 + hacks = Hack.select(select_sql).published.opening.merge(Hack.select(select_sql).unpublish.mine(current_user.id)) end # 搜索 if params[:search] diff --git a/app/models/hack.rb b/app/models/hack.rb index adc6bba8c..814debef5 100644 --- a/app/models/hack.rb +++ b/app/models/hack.rb @@ -12,6 +12,7 @@ class Hack < ApplicationRecord belongs_to :user scope :published, -> { where(status: 1) } + scope :unpublish, -> { where(status: 0) } scope :opening, -> {where(open_or_not: 1)} scope :mine, -> (author_id){ where(user_id: author_id) }