开发者

What's the Rails Way to get the Model Class from the Controller?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜