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

···

--
Posted via http://www.ruby-forum.com/.

Kernel.const_get(model)

Christopher

···

On 3/3/08, Sijo Kg <sijo@maxxion.com> wrote:

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.

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

"ServiceDesk".constantize.new

~ j.

···

On Mon, Mar 3, 2008 at 1:39 AM, Sijo Kg <sijo@maxxion.com> 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?

Hi,

···

On Mon, Mar 3, 2008 at 8:47 PM, Christopher Swasey < christopher.swasey@gmail.com> wrote:

Kernel.const_get(model)

And hence Kernel.const_get(model).new.

Arlen