Freeze field in active record

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:indefine_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:indefine_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!

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. [email protected]

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

On Jul 31, 4:20 pm, Christophe [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs