app/models/user.rb
# Gives collection of last user activities (Topics and posts)
Gives collection of last user activities (Topics and posts)
Gives collection of last user activities ( Topics and posts )
def recent_activities(count: 10)
    posts  = Post.reorder(updated_at: :desc).where(user_id: id).limit(count)
    topics = Topic.reorder(updated_at: :desc).where(user_id: id).limit(count)
    activities = posts + topics
    activities.sort! { |x, y| y.updated_at <=> x.updated_at }
    activities.first(count)
  end
def recent_activities ( count : 10 ) posts = Post . reorder ( updated_at : :desc ) . where ( user_id : id ) . limit ( count ) topics = Topic . reorder ( updated_at : :desc ) . where ( user_id : id ) . limit ( count ) activities = posts + topics activities . sort! { | x , y | y . updated_at <=> x . updated_at } activities . first ( count ) end
Gives collection of last user activities (Topics and posts)
Gives collection of last user activities ( Topics and posts )
count
<not_specific>