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.
A025f68d8100c2f0fa78c6cfcc4cbfd1?d=identicon&s=25 James Mccarthy (noagenda)
on 2006-03-22 01: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?
36df5a25b0f7e1a39826370b91497167?d=identicon&s=25 Charles Leeds (Guest)
on 2006-04-28 00: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 Leeds
3ccdcc71db4c8212fba584953572bf51?d=identicon&s=25 Noel R. Morais (Guest)
on 2006-05-30 07:18
(Received via mailing list)
Charles, i have the same problem, did you solve this?

Thanks,

--
_________
Noel R. Morais
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-05-30 08:35
Charles Leeds 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 Susser
http://blog.hasmanythrough.com
Bc7279484cc8b64ab5fd643832873955?d=identicon&s=25 cyx (Guest)
on 2006-05-30 10:23
alternatively you can use a declarative approach and put

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