# Activerecord model constantize question

**URL:** <https://www.ruby-forum.com/t/activerecord-model-constantize-question/110636>\
**Category:** Rails\
**Created:** [July 28, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/activerecord-model-constantize-question/110636 "2007-07-28T17:26:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![izit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/87869e/32.png) [@izit](https://www.ruby-forum.com/u/izit)\
**Post date:** [July 28, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/activerecord-model-constantize-question/110636/1 "2007-07-28T17:26:26Z")

</div>

I have a variable called column with the value of “bla” (column =  
“bla”)

I have a model call Location where method bla is defined (amongst many  
other methods). What I would like to to is to call the method in  
Location defined in the variable column.

I tried:

Location.column.constantize

but that gave me an error NoMethod.

I am sure there is a very simple way in Ruby as always 🙂

who can help me?

thanks

---

<div class="post-metadata">

**Author:** ![izit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/87869e/32.png) [@izit](https://www.ruby-forum.com/u/izit)\
**Post date:** [July 28, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/activerecord-model-constantize-question/110636/2 "2007-07-28T17:39:28Z")

</div>

bitterbal wrote:

> I have a variable called column with the value of “bla” (column =  
> “bla”)
> 
> I have a model call Location where method bla is defined (amongst many  
> other methods). What I would like to to is to call the method in  
> Location defined in the variable column.

you can use Ruby’s send[1] method on the location object with the column  
name. Like so:

column = “bla”  
my\_location = Location.find(1)  
my\_location.send(column) # calls mylocation.bla

[1] [class Object - RDoc Documentation](http://www.ruby-doc.org/core/classes/Object.html#M000334)

* * *

Ryan Carmelo Briones

–  
View this message in context:  
[http://www.nabble.com/activerecord-model-constantize-question-tf4162558.html#a11843879](http://www.nabble.com/activerecord-model-constantize-question-tf4162558.html#a11843879)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![izit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/87869e/32.png) [@izit](https://www.ruby-forum.com/u/izit)\
**Post date:** [July 28, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/activerecord-model-constantize-question/110636/3 "2007-07-28T17:42:28Z")

</div>

Thanks ! I was already reading through the API docs did not find it  
yet

On Jul 28, 5:38 pm, Ryan Carmelo Briones
