# How to know if model attribute is protected?

**URL:** <https://www.ruby-forum.com/t/how-to-know-if-model-attribute-is-protected/127252>\
**Category:** Rails\
**Created:** [January 27, 2008, 4:17am UTC](https://www.ruby-forum.com/t/how-to-know-if-model-attribute-is-protected/127252 "2008-01-27T04:17:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [January 27, 2008, 4:17am UTC](https://www.ruby-forum.com/t/how-to-know-if-model-attribute-is-protected/127252/1 "2008-01-27T04:17:48Z")

</div>

I’m adding some meta-methods to a plugin and would really like to be  
able to know if an attribute is protected or not in my model.  
Unusually, googing hasn’t turned up an answer. I know I could try an  
assignment and then rescue the exception (assuming the default whiny  
behaviour is on) but thats not a pleasing approach.

Thanks for any help or pointers,

–Kip

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [January 27, 2008, 4:45am UTC](https://www.ruby-forum.com/t/how-to-know-if-model-attribute-is-protected/127252/2 "2008-01-27T04:45:25Z")

</div>

Its not in the API description for ActiveRecord::Base, but it is  
mentioned in the source code for attr\_protected.  
#protected\_attributes returns an array of the attributes that are  
protected.

–Kip
