Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8192565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:12:35+00:00 2026-06-07T04:12:35+00:00

I have an Activity stream I have designed using STI in rails 3. I

  • 0

I have an Activity stream I have designed using STI in rails 3.

I want to do a check to see if a user has more than 10 activity items on create. When a user creates his 11th Activity in the database, I want it to destroy the oldest record * essentially the first record the user made and so on.* This way I am keeping my database clean of thousands of old useless records.

I am assuming I would start at the model level, but since I dont want to define the “current_user” in the model, it should be in the controller.

Any help would be appreciated to accomplish this task, I am fairly new at these type of more advanced tasks in rails.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:12:36+00:00Added an answer on June 7, 2026 at 4:12 am

    You can hook this logic up in an AR callback. Assuming you kept rails conventions when modeling you classes, and each activity belongs to a user, you can then easily do the following in your Activity model:

    after_save do |record|
      if Activity.where(:user => record.user).count >= 11
        Activity.where(:user => record.user).order('created_at asc').first.destroy
      end
    end
    

    I guess this will create three transactions to the db (one for count, another to find the first record, and one to delete it). I wonder if there’s a more efficient way to do this, as it will be invoked on every Activity#save…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of activity stream items where I want similar items to
The application I'm working on has an activity feed where each user can see
in my app i have activity with XML layout, i want to build an
I have an Activity A that calls an Activity B using startActivityForResult() . Under
I'm building a small social site, and I want to implement an activity stream
I have a workflow service which receives a stream through a ReceiveRequest activity. The
I have a music stream app and I want to display a foreground notification
We have a patch model where we're intending on using cset.pl -findmerge <activity> to
I'm in the making of some kind of activity stream/feed using PHP and MySQL.
I have a multiple Activity application that progresses the user from entering an IP/Host

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.