# Attr\_readonly and if/unless

**URL:** <https://www.ruby-forum.com/t/attr-readonly-and-if-unless/174810>\
**Category:** Rails\
**Created:** [September 2, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/attr-readonly-and-if-unless/174810 "2009-09-02T17:17:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felix\_SchSSS\_fer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ed8c4c/32.png) [@Felix\_SchSSS\_fer](https://www.ruby-forum.com/u/Felix_SchSSS_fer)\
**Post date:** [September 2, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/attr-readonly-and-if-unless/174810/1 "2009-09-02T17:17:16Z")

</div>

Hello,

I tried to apply attr\_readonly :some, :attributes to all none root-  
nodes of an acts\_as\_tree model. The important part here is that:  
“”"  
attr\_readonly :some, :attributes unless some\_condition  
“”"  
doesn’t seem to work: all objects have :some and :attributes set to  
read\_only, even if they meet some\_condition. After searching for that  
a little bit, I discovered that it had been corrected in bugmash not  
that long ago (and now that I mention it, I can only find this ML-post

> **[OSDIR](https://osdir.com)**
>
> edit post Gaming How To Check If US iGaming Platform is Safe July 13, 2021 edit post Gaming What made

…).

Anyway, does anyone know a way how to get this behaviour on 2.3.3  
(other than writing custom setters, of course…)?

Thanks,

Felix

---

<div class="post-metadata">

**Author:** ![Felix\_SchSSS\_fer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ed8c4c/32.png) [@Felix\_SchSSS\_fer](https://www.ruby-forum.com/u/Felix_SchSSS_fer)\
**Post date:** [September 2, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/attr-readonly-and-if-unless/174810/2 "2009-09-02T17:22:32Z")

</div>

On Sep 2, 3:28 pm, Felix Schäfer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> that long ago (and now that I mention it, I can only find this ML-posthttp://osdir.com/ml/RubyonRails:Core/2009-03/msg00022.html  
> …).
> 
> Anyway, does anyone know a way how to get this behaviour on 2.3.3  
> (other than writing custom setters, of course…)?

Well you could see if the patch that was written for this applies  
cleanly to 2.3.3 or can be turned into a small plugin.

Fred
