How do I substitute variables into class names?


#1

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?


#2

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.


#3

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

Thanks,


Noel R. Morais


#4

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.

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000879

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

def inheritance_column
“flavor”
end


Josh S.
http://blog.hasmanythrough.com


#5

alternatively you can use a declarative approach and put

set_inheritance_column “whatever”