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

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.

Could you not be writing model = ServiceDesk, in which case the
problem completely goes away? If not you can use model = "ServiceDesk".constantize

Fred

Hi      Thanks for your reply.It worked

Sijo

Why not:

ServiceDesk.find(29)

What role does the string play in this?

Because in model="ServiceDesk"

"ServiceDesk" is one of the fiels of a table of type String.And there is also other entries in that field like Incident,etc.All are names of ActiveRecord modelclasses

Sijo