# Freeze field in active record

**URL:** <https://www.ruby-forum.com/t/freeze-field-in-active-record/144633>\
**Category:** Rails\
**Created:** [July 31, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/freeze-field-in-active-record/144633 "2008-07-31T17:41:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![christophe1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b3f665/32.png) [@christophe1](https://www.ruby-forum.com/u/christophe1)\
**Post date:** [July 31, 2008, 5:41pm UTC](https://www.ruby-forum.com/t/freeze-field-in-active-record/144633/1 "2008-07-31T17:41:50Z")

</div>

Hello,

I have a freeze field in a table (that I can’t change).  
When I try to find a record in this table I have the exception :

```
C:/DATA/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/

```

activerecord-2.1.0/lib/active\_record/attribute\_methods.rb:104:in  
`instance_method_already_implemented?' C:/DATA/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.1.0/lib/active_record/attribute_methods.rb:72:in`define\_attribute\_methods’  
C:/DATA/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/  
activerecord-2.1.0/lib/active\_record/attribute\_methods.rb:71:in `each' C:/DATA/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.1.0/lib/active_record/attribute_methods.rb:71:in`define\_attribute\_methods’  
C:/DATA/InstantRails-2.0/ruby/lib/ruby/gems/1.8/gems/  
activerecord-2.1.0/lib/active\_record/attribute\_methods.rb:238:in  
`method\_missing’

any idea to avoid the problem?  
Is it possible to change the name of the attribute in the active  
record class ?

Many thanks!

---

<div class="post-metadata">

**Author:** ![christophe1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b3f665/32.png) [@christophe1](https://www.ruby-forum.com/u/christophe1)\
**Post date:** [July 31, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/freeze-field-in-active-record/144633/2 "2008-07-31T18:06:30Z")

</div>

Thanks for the answer,  
but the problem comes frome the freeze method,  
It throws :

ActionView::TemplateError (freeze is defined by ActiveRecord) on line  
#75 of promo\_structural/\_promo\_v2.rhtml:

when I execute any access to my ActiveRecord, even to other attributes

Christophe

On Jul 31, 5:43 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![christophe1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b3f665/32.png) [@christophe1](https://www.ruby-forum.com/u/christophe1)\
**Post date:** [July 31, 2008, 6:12pm UTC](https://www.ruby-forum.com/t/freeze-field-in-active-record/144633/3 "2008-07-31T18:12:57Z")

</div>

On 31 Jul 2008, at 17:05, Christophe wrote:

> Thanks for the answer,  
> but the problem comes frome the freeze method,  
> It throws :
> 
> ActionView::TemplateError (freeze is defined by ActiveRecord) on line  
> #75 of promo\_structural/\_promo\_v2.rhtml:
> 
> when I execute any access to my ActiveRecord, even to other attributes

Ah yes, that actually makes sense. I suppose you could use a select  
option to select the column with another name (ie select foo as bar).  
Can’t think of another way out without hacking around with the  
activerecord code (if I was going to do that I would change  
raise DangerousAttributeError, “#{method\_name} is defined by  
ActiveRecord” if @@\_defined\_activerecord\_methods.include?(method\_name)  
to  
return true if @@\_defined\_activerecord\_methods.include?(method\_name)  
(in attribute\_methods.rb))

Fred

---

<div class="post-metadata">

**Author:** ![christophe1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b3f665/32.png) [@christophe1](https://www.ruby-forum.com/u/christophe1)\
**Post date:** [July 31, 2008, 5:44pm UTC](https://www.ruby-forum.com/t/freeze-field-in-active-record/144633/4 "2008-07-31T17:44:47Z")

</div>

On Jul 31, 4:20 pm, Christophe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,
> 
> I have a freeze field in a table (that I can’t change).  
> When I try to find a record in this table I have the exception :

Ruby objects already have a freeze method (it makes the object  
immutable).

The easiest way out is probably to write your own accessor methods:

def some\_other\_name  
self[:freeze]  
end

def some\_other\_name= value  
self[:freeze] = value  
end

Fred
