Typecast

Hi
I have an ActiveRecord class ServiceDesk and a string “ServiceDesk”
.How can I convert the string “ServiceDesk” to create a new object of
the class ServiceDesk?

Concept is made clear below.

model = “ServiceDesk” // Now the variable, model, contains the string
“ServiceDesk” which is the name of an active record class.

I am trying to achieve the following. how can I really achieve this…
Thanks in advance.

model.find(29)

Sijo

On 3/3/08, Sijo Kg [email protected] wrote:

Kernel.const_get(model)

Christopher

Hi,

On Mon, Mar 3, 2008 at 8:47 PM, Christopher S. <
[email protected]> wrote:

Kernel.const_get(model)

And hence Kernel.const_get(model).new.

Arlen

On Mon, Mar 3, 2008 at 1:39 AM, Sijo Kg [email protected] wrote:

I have an ActiveRecord class ServiceDesk and a string “ServiceDesk”
.How can I convert the string “ServiceDesk” to create a new object of
the class ServiceDesk?

Since you’re working with Rails and therefore ActiveSupport, you can do:

“ServiceDesk”.constantize.new

~ j.