how to get the model name of an AR instance

I have a polymorphic class Event

class Event < ActiveRecord::Base
  belongs_to :taskable, :polymorphic => true

so an event.instance has : event.taskable_type and
i.e. event[:taskable_type] = "Project" event[:taskable_id] = 2

Is it possible to localize the taskable_type ( "Project") using
Model.model_name.human ? taskable_type is a string...

I tried to get it from the instance ,
event.taskable.model_name.human, but model_name is not an AR instance
( NoMethodError: undefined method `human_name' for #<Project...>

See the method constantize.

I think I found it … (taskable is the instance, but model_name needs to

run on the class, so add .class):

Contact belongs_to :person

011:0> contact.person.model_name

NoMethodError: undefined method `model_name’ for #Person:0xaa16a44

012:0> contact.person.class.model_name

=> “Person”

I have not tried on polymorphic, but I presume it would work too.



thanks Everaldo that's it ... ( maybe the first time I use it... !)

as per your answer + Evaraldo's one :
event.taskable.class.constantize.model_name on polymorphic works