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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:49:43+00:00 2026-05-12T21:49:43+00:00

Wondering if there’s a plugin or best way of setting up an ActiveRecord class

  • 0

Wondering if there’s a plugin or best way of setting up an ActiveRecord class so that, for example, when a record enter the “published” state, certain attributes are frozen so that they could not be tampered with.

  • 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-12T21:49:44+00:00Added an answer on May 12, 2026 at 9:49 pm

    You can freeze an entire AR::B object by setting @readonly to true (in a method), but that will lock out all attributes.

    The way I would recommend is by defining attribute setter methods that check for the current state before passing to super:

    class Post < ActiveRecord::Base
      def author=(author)
        super unless self.published?
      end
    
      def content=(content)
        super unless self.published?
      end
    end
    

    [EDIT] Or for a large amount of attributes:

    class Post < ActiveRecord::Base
      %w(author content comments others).each do |method|
        class_eval <<-"end_eval", binding, __FILE__, __LINE__
          def #{method}=(val)
            super unless self.published?
          end
        end_eval
      end
    end
    

    Which of course I would advocate pulling into a plugin to share with others, and add a nice DSL for accessing like: disable_attributes :author, :content, :comments, :when => :published?

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

Sidebar

Related Questions

Wondering if there is any way to get the lambda expressions that result from
Wondering if there is a good way to generate temporary URLs that expire in
I was wondering if there was a plugin or best practice for pushing the
I'm wondering the best way to separate my plugin's templates from the actual logic.
Just wondering if there is a plugin out there that abstracts the process of
I was wondering if there is a programmatically way to install zen coding plugin.
I was wondering if there is a plugin that allows me to jump directly
As a graphic designer, I am wondering if either: there is a WordPress plugin
Wondering if there is any tool that can help me to detect a pronoun's
just wondering if there is a way to reduce the amount of code needed

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.