Tag: classname

在rubyonrails中,如何从ActiveRecord :: Relation对象获取关联的模型类?

假设我有一个模型: class Post end posts = Post.where(***) puts posts.class # => ActiveRecord::Relation 那么如何通过变量’posts’获取模型类名,也许是一些名为model_class_name的方法: put posts.model_class_name#=>发布 谢谢 :)