How to dynamically call a class method in ruby

Say that I have a model name stored in a variable:

"#{class_name.singularize}" 

from another controller. I want to see the columns defined for this model. I tried

 send("#{class_name.singularize}.columns") 

but he is trying to call Page.columns as a method of the class I'm working on now, not the Page class. Any ideas on how to do this?

+8
ruby ruby-on-rails ruby-on-rails-3
source share
1 answer

Use constantize :

 class_name.singularize.constantize.columns 
+13
source share

All Articles