I can do this in the controller to get the model class:
self.class.name.gsub("Controller", "").singularize.constantize
But is there a built in method for this in the controller?
Something like self.model_class
?
Thanks开发者_运维百科!
params[:controller].classify.constantize
ActionPack
and ActiveRecord
are separate modules, so there's no built-in support for that.
Another way:
controller_name.classify
精彩评论