# How do I substitute variables into class names?

**URL:** <https://www.ruby-forum.com/t/how-do-i-substitute-variables-into-class-names/55545>\
**Category:** Rails\
**Created:** [March 22, 2006, 1:04am UTC](https://www.ruby-forum.com/t/how-do-i-substitute-variables-into-class-names/55545 "2006-03-22T01:04:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [March 22, 2006, 1:04am UTC](https://www.ruby-forum.com/t/how-do-i-substitute-variables-into-class-names/55545/1 "2006-03-22T01:04:04Z")

</div>

In a partial that renders another partial, I would like to change the  
items I am rendering based on the content of a variable. So instead of  
having 5 partials which all have variations on this;

\<% for @skill in @cv.skills %\>  
\<%= render :partial =\> “skills” %\>  
\<% end %\>

If item = “skill” would like to do something to this effect;

\<% eval(“for @#{item} in @cv.#{item}s”) %\>  
\<%= render :partial =\> “#{item}s”, :local =\> {:item =\> “skill”} %\>  
\<% end %\>

But this does not work… anybody got any ideas?

---

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [April 28, 2006, 12:03am UTC](https://www.ruby-forum.com/t/how-do-i-substitute-variables-into-class-names/55545/2 "2006-04-28T00:03:30Z")

</div>

I am running Rails 1.1.2.

I am working with a Microsoft SQL Server database for a purchased  
application and it has a field named “Type”, which is a reserved word in  
Ruby on Rails. Is there any way to customize my model so that I can use  
ActiveRecord.find on the table instead of having to use the “execute”  
method and manually write SQL code for everything? Changing the field  
name is unfortunately not possible.

Thanks,

Charles L.

---

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [May 30, 2006, 7:18am UTC](https://www.ruby-forum.com/t/how-do-i-substitute-variables-into-class-names/55545/3 "2006-05-30T07:18:18Z")

</div>

Charles, i have the same problem, did you solve this?

Thanks,

–

* * *

Noel R. Morais

---

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [May 30, 2006, 8:35am UTC](https://www.ruby-forum.com/t/how-do-i-substitute-variables-into-class-names/55545/4 "2006-05-30T08:35:45Z")

</div>

Charles L. wrote:

> I am working with a Microsoft SQL Server database for a purchased  
> application and it has a field named “Type”, which is a reserved word in  
> Ruby on Rails. Is there any way to customize my model so that I can use  
> ActiveRecord.find on the table instead of having to use the “execute”  
> method and manually write SQL code for everything? Changing the field  
> name is unfortunately not possible.

The field “type” is used for STI (Single Table Inheritance), but you can  
override it in your model class.

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000879)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

To change it to “flavor”, put the following in your model class:

def inheritance\_column  
“flavor”  
end

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![noagenda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8c91f0/32.png) [@noagenda](https://www.ruby-forum.com/u/noagenda)\
**Post date:** [May 30, 2006, 10:23am UTC](https://www.ruby-forum.com/t/how-do-i-substitute-variables-into-class-names/55545/5 "2006-05-30T10:23:40Z")

</div>

alternatively you can use a declarative approach and put

set\_inheritance\_column “whatever”
