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

  • Home
  • SEARCH
  • 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 7637391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:55:36+00:00 2026-05-31T07:55:36+00:00

I have a Photo object and an Activity observer. Activities are basically just a

  • 0

I have a Photo object and an Activity observer.

Activities are basically just a listing of recent activities around the site (photo uploaded, comment made, etc).

Right now I have a before_destroy method in the Activity observer so that when an object (such as a photo) is destroyed, it will remove the activity from the listing of recent activities.

But what I need to do is sort of fake the destroy action for the photo.

We don’t actually destroy the record in the database when someone “deletes” their photo, we just mark it as inactive.

But since I’m using observers, how can I still trigger that before_destroy method in the Activity observer when a user fires the Photo.destroy method?

Here is the basic code for both the Photo object and the observer…

class PhotosController < ApplicationController
  def destroy
    @photo.update_attribute(:active, false)
  end
end


class ActivitySourceObserver < ActiveRecord::Observer
  observe :photo

  def before_destroy(activity_source)
    Activity.destroy_all(:activity_source_id => activity_source.id)
  end
end
  • 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-05-31T07:55:37+00:00Added an answer on May 31, 2026 at 7:55 am

    As you are updating the resource rather than deleting it, could you not use a before_update method?

    class PhotosController < ApplicationController
      def destroy
        @photo.update_attribute(:active, false)
      end
    end
    
    class ActivitySourceObserver < ActiveRecord::Observer
      observe :photo
    
      def before_update(activity_source)
        if activity_source.has_attribute? :active && activity_source.active == false
          Activity.destroy_all(:activity_source_id => activity_source.id)
        end
      end
    end
    

    I’ve not tested this but I hope you see what I mean.

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

Sidebar

Related Questions

I have this rabl template: object @photo attributes :id child :comments do attributes :id,
I have a Player class that uses a ForeignKey to a Photo object for
Suppose I have a Contact object with a name and photo only @interface Contact:
Hay I have a model like this def Photo(models.Model): # Photo object fields... def
How get my OWN comments, likes, actions just like my wall's recent activity shows
If i have an object of type Photo and a Result set which is
I have photo gallery code that does image re-sizing and thumbnail creation. I use
I have a photo website and i want to support tags as my original
I have a photo gallery web page where a single <img src="XXX" /> element's
I have a photo gallery I would like that every time a user does

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.