试图在Rails关注中获取封闭类的名称

时间:2015-08-11 21:04:52

标签: ruby-on-rails activesupport-concern

首次使用问题而只是寻求一些建议。

我有一个名为location.rb的Rails模型,并希望包含一个AlbumDefineConcern,然后查询我们当前所在的模型类(在此类Location中)。

我有:

class Location < ActiveRecord::Base
  include AlbumDefineConcern
  ...

module AlbumDefineConcern
  extend ActiveSupport::Concern
  albums={}
  albums_locations = ["LocationHomeFeed","LocationProfile","LocationMobileMain"]
  albums[:locations]=albums_locations
  # I'd like it to output location or Location
  puts "here is class_name #{self.name}" 

我如何获得&#34; location&#34;作为班级名称?

#  puts "here is class_name #{self.parent.name}" => Object

1 个答案:

答案 0 :(得分:2)

module AlbumDefineConcern
    extend ActiveSupport::Concern

    included do
        puts self
    end

end