Forum: Ruby on Rails How do I substitute variables into class names?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James M. (Guest)
on 2006-03-22 02:04
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?
Charles L. (Guest)
on 2006-04-28 02:03
(Received via mailing list)
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.
Noel R. Morais (Guest)
on 2006-05-30 09:18
(Received via mailing list)
Charles, i have the same problem, did you solve this?

Thanks,

--
_________
Noel R. Morais
Josh S. (Guest)
on 2006-05-30 10:35
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/Ba...

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

def inheritance_column
  "flavor"
end

--
Josh S.
http://blog.hasmanythrough.com
cyx (Guest)
on 2006-05-30 12:23
alternatively you can use a declarative approach and put

set_inheritance_column "whatever"
This topic is locked and can not be replied to.