# Alias\_method on a model

**URL:** <https://www.ruby-forum.com/t/alias-method-on-a-model/72908>\
**Category:** Rails\
**Created:** [October 19, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/alias-method-on-a-model/72908 "2006-10-19T20:25:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 19, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/alias-method-on-a-model/72908/1 "2006-10-19T20:25:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 19, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/alias-method-on-a-model/72908/2 "2006-10-19T20:42:14Z")

</div>

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  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 19, 2006, 8:48pm UTC](https://www.ruby-forum.com/t/alias-method-on-a-model/72908/3 "2006-10-19T20:48:16Z")

</div>

On 10/19/06, Daniel H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 19, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/alias-method-on-a-model/72908/4 "2006-10-19T23:23:41Z")

</div>

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  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 20, 2006, 2:34am UTC](https://www.ruby-forum.com/t/alias-method-on-a-model/72908/5 "2006-10-20T02:34:16Z")

</div>

Thanks everyone!

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [October 19, 2006, 10:30pm UTC](https://www.ruby-forum.com/t/alias-method-on-a-model/72908/6 "2006-10-19T22:30:40Z")

</div>

Lance I. wrote:

> Nope. Attribute access is implemented through method\_missing

Really? Looking at the source, method\_missing is used for dynamic  
finders.

Joe
