I wanted to know is it possible to do the following 2 things at once:
- View all items with status
published
. - View items for current user with any status.
I have this code:
# Item model
scope :published, -> { where(status: 'published') }
scope :unpublished, -> { where.not(status: 'published') }
scope :by_user, -> (user_id) { where(user: user_id) }
# Item controller
def index
@items = Item.published + Item.unpublished.by_user(current_user.id)
end
The problem is that @items
are an Array
, but I want ActiveRecord::Relation
.
If you want to know why I need this, it's a simple answer:
@items.find(params[:id])