Alias_method on a model

Is there a way to alias an automaically created model attribute? I have
a
column named start_time, and when I use

alias_method :default_start_time, :start_time

In the model’s class definition, I get an “undefined method” error

Thanks!
Daniel

Nope. Attribute access is implemented through method_missing, which
means that the method you’re trying to alias just won’t exist. You can
still alias things the “long” way:

def default_start_time
start_time
end

or on one line, if you prefer:

def default_start_time; start_time end

Daniel H. wrote:


Lance I.
Web Applications Developer
RBS Interactive
[email protected]

On 10/19/06, Daniel H. [email protected]
wrote:

Is there a way to alias an automaically created model attribute? I have a
column named start_time, and when I use

alias_method :default_start_time, :start_time

In the model’s class definition, I get an “undefined method” error

Try alias_attribute.

jeremy

Yeah, it’s easy enough to miss: the method_missing defined on line 1090
(activerecord 1.14.4, base.rb) implements the dynamic finders for the
class, and the method_missing defined further down on line 1770
implements attribute access for the instances. They’re used in different
contexts (e.g. Person.find_by_first_name vs person.first_name).

Joe R. MUDCRAP-CE wrote:


Lance I.
Web Applications Developer
RBS Interactive
[email protected]

Thanks everyone!

Lance I. wrote:

Nope. Attribute access is implemented through method_missing

Really? Looking at the source, method_missing is used for dynamic
finders.

Joe