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 9160627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:46:59+00:00 2026-06-17T13:46:59+00:00

I have two models one of them is a User, and another Comments. Comments

  • 0

I have two models one of them is a User, and another Comments. Comments belong to User.

class User < ActiveRecord::Base
    act_as_paranoid
    has_many :comments
end

class Comment < ActiveRecord::Base
    belongs_to :user
end

When I do user.delete in my controller I get the expected result of the deleted_at column being set and the record being hidden.

My problem is the Comment associations for the user are set to null. So now on the site it shows no user owning the comment. I’d like the comment to still show the user’s name not be “None” or “Anonymous” etc.

Looking at the source on github https://github.com/goncalossilva/rails3_acts_as_paranoid/blob/rails3.2/lib/acts_as_paranoid/core.rb it seems to call run_callbacks which in turn results in Rails 3 falling back to Nullify default for associations.

In my case I just want the user account to be closed off when deleted. Not showing up in queries anymore so that Authlogic will deny them and the User index page won’t show them. But still allowing everything a user owns to still be owned by them (since they may come back, etc.).

Is there a better way to do this then acts_as_paranoid?

  • 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-17T13:47:00+00:00Added an answer on June 17, 2026 at 1:47 pm

    Rather then go to the trouble of overriding the destroy method I created a close method that simply sets closed_at to a timestamp. If you set default scope to something like:

    default_scope { where("closed_at IS NULL") }
    

    Then the model won’t show up to any queries including User.All. You can delete the scope to get a full query essentially I took these ideas from act_as_paranoid but much more simplified. The problem is that then even though the Comments still have user_id set, the default scope runs with any association load. So say

    c = Comment.first
    c.user
    

    That will output nil if user_id is a closed account. In my case the easiest solusion was to remove default scoping and modify my Authlogic function to:

    def self.find_by_username_or_email(login)
      u = User.find(:first, :conditions => ["lower(username) = ?", login.downcase]) || User.find_by_email(login)
      return u unless u.closed_at  
    end
    

    This way closed accounts can’t login. Anywhere I list out users in my views I used a hide_closed scope.

    Not sure if this was the best most elegant solution. But for my purposes it works.

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

Sidebar

Related Questions

I have two models: User (email:string) Profile (name:string) class User < ActiveRecord::Base has_one :profile
I have the following two models: class Parent < ActiveRecord::Base has_one :child, dependent: :destroy
I have two models user and biography , both of them have one to
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
Say I have two models and one belongs to another. Now normaly you would
I have two models, one a vanilla Django model, another an unmanaged model wrapping
I have two models. one is brand and another is product_detail. brands table has
I have two models, A and B, and one light, L. I would like
If I have two models that are guaranteed to have a one-to-one correspondence, i.e.
I have two models generated with generate scaffolding, one is a LogBook the other

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.